Videos
Hey folks, this is baffling me - how do I create a new app/get API credentials?
When I go to /pref/apps I just get a "You are already logged in and will be redirected"
But when I get redirected I end up on the same screen.
Any insights? :-)
Thanks!
As of right now, you cannot retrieve a permanent access token. You have 2 options that come close.
The first is to request a "refresh" token when using the standard OAuth flow. That's what you're doing by sending "duration" as "permanent" in your code. The refresh token can be used to automatically retrieve new 1 hour access tokens without user intervention; the only manual steps are on the initial retrieval of the refresh token.
The second alternative, which applies only when writing a script for personal use, is to use the password grant type. The steps are described in more detail on reddit's "OAuth Quick Start" wiki page, but I'll summarize here:
- Create an OAuth client (under https://www.reddit.com/prefs/apps) with type = "script"
- Make a request to
https://www.reddit.com/api/v1/access_tokenwith POST parametersgrant_type=password&username=<USERNAME>&password=<PASSWORD>. Send your client ID and secret as HTTP basic authentication.<USERNAME>must be registered as a developer of the OAuth 2 client ID you send.
A client_id and client_secret can be generated for a reddit account by going to https://www.reddit.com/prefs/apps and creating an app:
The part I have hidden is my client_id.
Then you can use a client like praw to access reddit e.g. with Python:
import praw
r = praw.Reddit(client_id='insert id here',
client_secret='insert secret here',
user_agent='insert user agent')
page = r.subreddit('aww')
top_posts = page.hot(limit=None)
for post in top_posts:
print(post.title, post.ups)
You could use your current browser's user agent, which can be easily found by google searching "what is my user agent" (among other ways).
Please change ALL of the following:
API key
Redirect URL
User-Agent (in Infinity)
Please don't just change the API key!!!!!!!!! And please use another app name without infinity in it 🥺.
I found many users had made some tutorials about how to use your own API key, like this post, but none of them mentioned the other two things. If you don't change all of them, reddit still knows you are using Infinity, but with your own key.
You can see more info here.
How do you authenticate?
The API docs live here: https://www.reddit.com/dev/api It includes no information on how to use your client id and secret to authenticate.
This Github page) describes the procedure, but it hasn't been updated in 4 years, and when I attempt it, the token request call pulls up an HTML web page vice a JSON response.
There's a Python wrapper called PRAW, but it seems to be a bit messy, and it's also not clear if it's current. In general, Libs tend to be overkill for these sorts of API.
Is the Reddit API current and supported? How do you authenticate? Thank you.
I want to use command line tool curl to change the Sidebar of my channel. is it possible use username and password only just like github api?
for example:
curl https://reddit.com/r/SpaceVim/api/site_admin -X POST -u wsdjeg:********* -d "{\"description\" : \"sss\"}"Although it's technically possible, this authentication method is deprecated. You should be using OAuth2 for this kind of thing. Most languages have an API wrapper that supports this endpoint as well.
WTF! why down voted? user can not post feature request in this channel?