Search code examples
pythonoauthredditpraw

How do I avoid login for messaging Using Python Praw script?


I have written a script to archive submissions and comments of a certain author on Reddit. When it detects a new post I have it pm me the content.

Currently I start the session like this...

client = praw.Reddit(user_agent=USER_AGENT)
client.set_oauth_app_info(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, redirect_uri="http://127.0.0.1:65010/authorize_callback")
 #log in for messaging
client.login(MY_USERNAME, MY_PASSWORD)

I see that using login is deprecated. What steps do I need to take to give my script permission to "privatemessage"? All the examples I can find use login and I am stumped.


Solution

  • You need the privatemessages OAuth Scope.
    Use it as a string in get_authorize_url(), as shown here: https://praw.readthedocs.io/en/stable/pages/oauth.html#step-3-getting-authorization-from-the-user

    List of all possible Scopes: https://praw.readthedocs.io/en/stable/pages/oauth.html#oauth-scopes