【发布时间】: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 thecommentThreads.listmethod with thevideoIdparameter set to retrieve comments for a video.
标签: python api youtube youtube-api youtube-data-api