【问题标题】:Can't get all comments from Youtube Data API V3 [Python]无法从 Youtube Data API V3 [Python] 中获取所有评论
【发布时间】:2018-07-05 09:01:57
【问题描述】:

我有一个 python 函数,它允许您从 youtube 视频中获取所有 cmets。因此我使用 youtube API v3 cmets.list 方法。

key = 'My Key'
textFormat = 'plainText'
part = 'snippet'
maxResult = '100'
order = 'relevance'
nextToken = ''
videoId = 'Ix9NXVIbm2A'

while(True):
        response = requests.get("https://www.googleapis.com/youtube/v3/commentThreads?&key="+key+"&part="+part+"&videoId="+idVideo +"&maxResults="+maxResult+"&order="+order+"&pageToken="+nextToken)

        data  = response.json() #kind - etag - ?nextPageToken

        if 'error' in data:
            print(data)
            break

        for item in data['items']:
            snippet = item["snippet"]
            toplevelcomment = snippet['topLevelComment']
            content = toplevelcomment['snippet']

            commentid = toplevelcomment['id']
            authorname = content['authorDisplayName']
            textOriginal = content['textOriginal']

                #lists
            commentids.append(commentid)
            authornames.append(authorname)
            textOriginals.append(textOriginal)


        if 'nextPageToken' in data:
            nextToken = data['nextPageToken']

        else:
            break

从 pageToken 到另一个的所有进展都很好。但是当达到 pageToken 编号 13 时,API 总是返回

{
'error': 
 {
 'errors': 
  [
   {
    'domain': 'youtube.commentThread', 
    'reason': 'processingFailure', 
    'message': 'The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the requests input is invalid. Check the structure of the <code>commentThread</code> resource in the request body to ensure that it is valid.', 
    'locationType': 'other', 
    'location': 'body'
   }
  ], 
 'code': 400, 
 'message': 'The API server failed to successfully process the request. While this can be a transient error, it usually indicates that the requests input is invalid. Check the structure of the <code>commentThread</code> resource in the request body to ensure that it is valid.'
 }
}

我正在使用有效的密钥,并且 pageToken 也是有效的(由 API 返回)

有人遇到同样的问题还是我做错了什么?

【问题讨论】:

  • 您的error 表示您使用的输入请求无效。如果可能,您可以在文档提供的code snippet 中获得想法。 It calls the commentThreads.list method with the videoId parameter set to retrieve comments for a video.

标签: python api youtube youtube-api youtube-data-api


【解决方案1】:

出现此错误是因为您的 api 限制已用尽。 Youtube 不时更改 api 的限制。

有时也会出现网络问题。一旦请求失败,您必须编写多次尝试的代码。

您可以在此处阅读完整文档 - [https://developers.google.com/youtube/v3/getting-started#quota][1]

最近,截至 2019 年 1 月 11 日,youtube 将配额数量从每天 100 万减少到 10K

当前版本 3 仅允许每天 10k 单位。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-05-07
    • 2017-05-29
    • 2018-04-14
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 2021-02-27
    • 2016-04-08
    相关资源
    最近更新 更多