我试图使用google-api-python-client,并且基本上尝试访问youtube频道的观看次数。
response = {'kind': 'youtube#channelListResponse', 'etag': 'ZTMivxEyhYPJqH2CZb0MvzTZ4ts', 'pageInfo': {'totalResults': 1, 'resultsPerPage': 5}, 'items': [{'kind': 'youtube#channel', 'etag': 'Yxjey4KVgrhWSNhMTq1m1_52CJ0', 'id': 'UCCezIgC97PvUuR4_gbFUs5g', 'statistics': {'viewCount': '49964323', 'subscriberCount': '692000', 'hiddenSubscriberCount': False, 'videoCount': '230'}}]}
如何获取viewCount值?
from googleapiclient.discovery import build
api_key = "(private)"
youtube = build('youtube', "v3", developerKey=api_key)
request = youtube.channels().list(
part="statistics",
forUsername="schafer5"
)
response = request.execute()
print(response)
在这种特定情况下,您可以执行以下操作:
response["items"][0]["statistics"]["viewCount"]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句