0

Here is the API response for retrieving comments of a YouTube video, taken from https://developers.google.com/youtube/2.0/developers_guide_protocol_comments:

<feed> <entry> ... <media:group> ... </media:group> <gd:comments> <gd:feedLink href='https://gdata.youtube.com/feeds/api/videos/VIDEO_ID/comments'/> </gd:comments> </entry> </feed> 

I am not sure which API to use to get this data. I have written my code in Python which gives me the author name and comment of a video. I want to fetch the timestamp of each comment for my research work.

1

1 Answer 1

0

Well, it would help to see the code you're using to get the author and comment text so I could give you the actual code that does it. But without that, looking at the API response, each comment is in an <entry> tag under the top-level <feed> tag.

For each comment there is both a <published> and an <updated> tag with timestamps. I'm guessing those are the date of the original comment and the date of the last edit. If I had your code to see how you're parsing the xml to begin with, I could probably add a snippet for you to retrieve those.

Edit: given the code in the link below. Here's a modification of the main loop that should do what you want.

for comment in comments_generator(client, VIDEO_ID): author_name = comment.author[0].name.text text = comment.content.text post_date = comment.published.text last_update_date = comment.update.text print("{}(date:{}): {}".format(author_name, post_date, text)) 

Note that the dates are in text format. If you want to extract python datetime objects from them, check out dateutil and this question.

Sign up to request clarification or add additional context in comments.

2 Comments

Traceback (most recent call last): File "comments_YT2.12.py", line 37, in <module> last_update_date = comment.update.text AttributeError: 'YouTubeVideoCommentEntry' object has no attribute 'update'
worked fine, i guess there is an attribute named published but not update, because i removed that line and i got the desired output, but there is something some attribute which can give us updated timestamp too. let me check.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.