How to get access token? (Reddit API)

前端 未结 2 963
名媛妹妹
名媛妹妹 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 14:05

    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:


    screenshot reddit.com/prefs/apps

    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).

提交回复
热议问题