Youtube数据Api在1000个结果后停止
我一直在尝试检索我的youtube频道的所有订户列表。我正在使用以下格式的查询:Youtube数据Api在1000个结果后停止,youtube,youtube-api,youtube-data-api,Youtube,Youtube Api,Youtube Data Api,我一直在尝试检索我的youtube频道的所有订户列表。我正在使用以下格式的查询: https://content.googleapis.com/youtube/v3/subscriptions?mySubscribers=true&maxResults=50&part=subscriberSnippet&access_token=xxxx 但是,在1000个结果之后(例如,20页@50页/页,或50页@20页/页),它停止。在文档中,它说对于myRecentSubscribers它应该只检索10
https://content.googleapis.com/youtube/v3/subscriptions?mySubscribers=true&maxResults=50&part=subscriberSnippet&access_token=xxxx
但是,在1000个结果之后(例如,20页@50页/页,或50页@20页/页),它停止。在文档中,它说对于
myRecentSubscribers
它应该只检索1000,但是对于mySubscribers
没有限制。有没有不成文的限制?我刚刚遇到了同样的问题,代码如下:
import os
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.readonly"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "google_oauth_client_secret.json"
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
next_page_token = ''
count = 0
while next_page_token != None:
print("Getting next page:", next_page_token, count)
request = youtube.subscriptions().list(
part="subscriberSnippet",
maxResults=50,
mySubscribers=True,
pageToken=next_page_token
)
response = request.execute()
next_page_token = response.get('nextPageToken')
subscribers = response.get('items')
for subscriber in subscribers:
count += 1
print('Total subscribers:', count)
if __name__ == "__main__":
main()
如果myRecentSubscribers=True
,这是预期的行为,但列表应继续使用mySubscribers=True
编辑:显然这是一个惯常的问题,文档可能最终会更新以反映。(我认为API正在阻止您,您可能需要一个密钥来扩展配额。谷歌搜索应该会发现这方面的信息。我目前正在使用一个密钥(从请求中删除以防止恶意使用)在您获得第一个1000后nextPageToken是否为空?在该点之后,请求中没有nextPageToken,只有PrevPageToken在加载第20页后,您可以包含任何错误消息吗?