Skip to main content

Reddit

"Reddit is an American social news aggregation, content rating, and discussion website. Registered users submit content to the site such as links, text posts, images, and videos, which are then voted up or down by other members. "

Configuration​

Getting Reddit OAuth credentials​

Start by accessing or creating a Reddit account.

If you do not already have a Client Id and Client Secret, you will first need to create them. Start by creating an app.

Click on the create another app button that will display a create application form. Select script from the radio input options.

Set your about uri and redirect uri to the following:

http://localhost

Set the name, and description and click the create app button.

Note: The client id is the value below the label that will say personal use script. The client secret is the value beside the secret label.

API terms and sign up for usage​

Goto https://www.reddit.com/wiki/api and click on read the full API terms and sign up for usage link. This will open a google form. Fill in the form fields the best you can. You will need your OAUTH Client ID(s) from Getting Reddit OAuth credentials (see **client id"").

Configuring Reddit OAuth Credentials in crul​

Navigate to the credentials page in crul (top right corner menu -> credentials).

Click the "create" button.

Select "OAuth" from the type dropdown, then select "Reddit" from the provider dropdown.

Copy the Client Id into the Client Id credentials form entry. Then copy the Client Secret into the Client Secret credentials form entry. See https://www.reddit.com/prefs/apps and look for the developed applications section for the respective Client Id and Client Secret values. Note: The Client Id is the value under the label personal use script

Test the credential by running the following query. You should see a populated token.access_token column in the results.

oauth --credential "reddit"

NOTE:​

When making any API request to reddit it is very important to follow the best practice of setting the useragent following the reddit useragent specification.

Example Flag:

--useragent "api:com.acmeinc:v1.0.0 (by u/acmeinc)"

Related Links: reddit OAuth2 spec || reddit auth management || reddit api rules.

Example queries​

Auth​

oauth
--auth.tokenHost "https://ssl.reddit.com"
--auth.tokenPath "/api/v1/access_token"
--client.id "${personal use script}"
--client.secret "${secret}"
--grant "clientcred"

These examples use the endpoints described in the Reddit API reference. Note: The root scheme/host for the Reddit API is https://oauth.reddit.com/

Example 1:​

Get the latest hot Sacramento subreddit topics.

oauth --credential "reddit"
|| api get https://oauth.reddit.com/r/sacramento/hot.json
--token.access_token "$token.access_token$"
--useragent "api:com.acmeinc:v1.0.0 (by u/acmeinc)"
|| normalize data.children

Example 2:​

Get all the latest hot Sacramento subreddit topic comments including the date created, subreddit and author.

oauth --credential "reddit"
|| api get https://oauth.reddit.com/r/sacramento/hot.json
--token.access_token "$token.access_token$"
--useragent "api:com.acmeinc:v1.0.0 (by u/acmeinc)"
|| normalize data.children
|| api get https://oauth.reddit.com$data.permalink$
--token.access_token "$token.access_token$"
--useragent "api:com.acmeinc:v1.0.0 (by u/acmeinc)"
|| normalize data.children
|| keyContains ".*body$" created subreddit author