无法从 Youtube Data API V3 [Python] 获得所有评论 [英] Can't get all comments from Youtube Data API V3 [Python]

查看:19
本文介绍了无法从 Youtube Data API V3 [Python] 获得所有评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a python function, which allows you to get all comments from a youtube video. Therefore I use the youtube API v3 comments.list method.

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总是返回

all progress good from pageToken to another. But when it reaches the pageToken number 13, the API always returns

{
'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 返回)

I'm using a valid key and the pageToken is valid too (returned by the API)

有没有人有同样的问题,或者我做错了什么?

Does anyone have the same problems or am I doing something wrong?

推荐答案

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

This error come because your api limits is exhausted. Youtube change the limit of api time to time.

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

And sometimes network problem is also occur. You have to write code for multiple attempt when once request is fail.

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

You can read full documentation here - [https://developers.google.com/youtube/v3/getting-started#quota][1]

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

Recently youtube decreased the quota numbers from 1M to 10K per day as of 11-January-2019

目前版本 3 只允许每天 10k 个单位.

currently version 3 allow only 10k units per day.

这篇关于无法从 Youtube Data API V3 [Python] 获得所有评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆