I'm trying to retrieve the last 1000 comments from a user since 1000 is the Reddit limit.
I followed the code example here, and modified a few of the calls for the updated API. Such as user.get_comments now seems to be just user.comments.
Here is the code I've run.
import praw
my_user_agent = 'USERAGENT'
my_client_id = 'CLIENTID'
my_client_secret = 'SECRET'
r = praw.Reddit(user_agent=my_user_agent,
client_id=my_client_id,
client_secret=my_client_secret)
user = r.redditor('REDDITUSERNAME')
for comment in user.comments(limit=None):
print comment.body
I get an error every time on the last line, though.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'SubListing' object is not callable
I have connected to the API and have an active connection as I can do print(user.comment_karma) and it displays correctly.
Any ideas what I'm doing wrong?
According to the documentation, comments
is an attribute of the Redditor
model in PRAW 4, not a function. Therefore, calling .comments(limit=None)
is invalid syntax because .comments
isn't a function. Instead, you must specify a listing sort order, like so, because SubListing
objects (what user.comments
is) inherit from BaseListingMixin
:
for comment in user.comments.new():
print(comment.body)
Admittedly, the documentation for PRAW 4 is very unclear, and you'll probably find the best documentation by searching through the code directly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With