按日期升序排列 YouTube 评论
我正在使用 YouTube Data API v3 从视频评论部分抓取所有顶级评论。我注意到请求的评论是按发布时间降序排列的(又名:最新的在前)。
有没有办法以相反的顺序对评论进行排序(又名:最旧的优先)?
我正在从 Python 发送我的请求。它看起来是这样的:
import json
import requests
# Build request
url = 'https://youtube.googleapis.com/youtube/v3/commentThreads?' + \
'part=snippet&' + \
'maxResults=50&' + \
'moderationStatus=published&' + \
'order=time&' + \ # Sort by time published
'textFormat=plainText&' + \
'videoId=ZpNHmDnHr6A&' + \ # Random video
'fields=' + \
'nextPageToken%2C%20' + \ # Get nextPageToken
'items(' + \ # Get textOriginal and publishedAt
'snippet%2FtopLevelComment%2Fsnippet%2FtextOriginal%2C%20' + \
'snippet%2FtopLevelComment%2Fsnippet%2FpublishedAt)&' + \
f'key={key}' # Your API Key here
# Response to dictionary
r = json.loads(requests.get(url).text)
I am using the YouTube Data API v3 to scrape all the top-level comments from a video's comment section. I noticed that the requested comments are ordered by the time they were posted in descending order (AKA: newest first).
Is there a way to sort comments in reverse order (AKA: oldest first)?
I am sending my requests from Python. This is what it looks like:
import json
import requests
# Build request
url = 'https://youtube.googleapis.com/youtube/v3/commentThreads?' + \
'part=snippet&' + \
'maxResults=50&' + \
'moderationStatus=published&' + \
'order=time&' + \ # Sort by time published
'textFormat=plainText&' + \
'videoId=ZpNHmDnHr6A&' + \ # Random video
'fields=' + \
'nextPageToken%2C%20' + \ # Get nextPageToken
'items(' + \ # Get textOriginal and publishedAt
'snippet%2FtopLevelComment%2Fsnippet%2FtextOriginal%2C%20' + \
'snippet%2FtopLevelComment%2Fsnippet%2FpublishedAt)&' + \
f'key={key}' # Your API Key here
# Response to dictionary
r = json.loads(requests.get(url).text)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论