Use PRAW to Interact With Posts and Comments
Learn how to get and make posts and comments using Python Reddit API Wrapper (PRAW).
We'll cover the following...
Make a post
We can make a post using the submit()
method. We'll need to provide the title and the body to submit the post.
Here are some important parameters we'll use to call the method:
Parameter | Type | Category | Description |
| string | required | The title we want in our new post. |
| string | required | The body of the post. |
Press "Run" to submit a new post to a subreddit.
Press + to interact
USERNAME
Not Specified...
CLIENT_SECRET
Not Specified...
CLIENT_ID
Not Specified...
SUBREDDIT_NAME
Not Specified...
REFRESH_TOKEN
Not Specified...
import prawimport jsonreddit = praw.Reddit(client_id="{{CLIENT_ID}}",client_secret="{{CLIENT_SECRET}}",refresh_token="{{REFRESH_TOKEN}}",user_agent="testscript by u/{{USERNAME}}")try:subreddit = reddit.subreddit("{{SUBREDDIT_NAME}}")title = "Sample title"selftext = "Heyyy from PRAW!"response = subreddit.submit(title=title,selftext=selftext)print(response)except Exception as e:print(e)
Lines 4–9: We initialize the Reddit
class, the parameters are explained here.
Line 11: We obtain an instance of the Subreddit
class.
Lines 12–13: ...