PRAW: How to get a reddit comment object with just the comment ID?
Asked Answered
G

2

6

I'm working on a bot where I only have the comment IDs, e.g., t1_asdasd. I don't have access to the parent thread or anything. Can I pull the corresponding comment object with just the comment ID?

Genvieve answered 20/12, 2013 at 5:7 Comment(0)
G
8

This reddit thread shows how to accomplish this through the normal API: http://www.reddit.com/r/redditdev/comments/1si9m0/fetching_comments_by_id/

Here's the code to do this with PRAW:

import praw
r = praw.Reddit(user_agent="bot by /u/{0}".format("YOUR-USERNAME")) 
submission = r.get_info(thing_id="t1_asdasd")
print(submission)
Genvieve answered 20/12, 2013 at 20:28 Comment(0)
N
5

praw.Reddit doesn't seem to have .get_info() anymore, so the answer above is no longer valid

Found that this returns the required comment:

comment_id = some_comment.id.split("_")[1]
praw.Reddit(required credentials).comment(id=comment_id)
Numeral answered 4/6, 2021 at 17:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.