How to get access token? (Reddit API)

前端 未结 2 968
名媛妹妹
名媛妹妹 2021-02-02 13:20

I wonder if it is possible to get a permanent access token for personal use on Reddit? It will only be me using the App.

For users, the access token expires after 1 hour

2条回答
  •  佛祖请我去吃肉
    2021-02-02 13:44

    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:

    1. Create an OAuth client (under https://www.reddit.com/prefs/apps) with type = "script"
    2. Make a request to https://www.reddit.com/api/v1/access_token with POST parameters grant_type=password&username=&password=. Send your client ID and secret as HTTP basic authentication. must be registered as a developer of the OAuth 2 client ID you send.

提交回复
热议问题