Can't get all comments from Youtube Data API V3 [Python]

百般思念 提交于 2019-12-11 09:49:11

问题


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

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.'
 }
}

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?

来源:https://stackoverflow.com/questions/48454296/cant-get-all-comments-from-youtube-data-api-v3-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!