按日期升序排列 YouTube 评论

发布于 2025-01-14 06:40:56 字数 997 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文