我从python脚本的youtube analytics api中收到空行响应。在15天之前,我可以正常工作,但现在却无法正常工作。
我已经尝试从
更改范围[“ https://www.googleapis.com/auth/yt-analytics.readonly”]到[“ https://www.googleapis.com/auth/youtube.readonly”],但没有用。
import os
from oauth2client.file import Storage
from oauth2client.tools import run_flow
from oauth2client.client import flow_from_clientsecrets
from apiclient.discovery import build
import httplib2
scopes = ["https://www.googleapis.com/auth/yt-analytics.readonly"]
MISSING_CLIENT_SECRETS_MESSAGE = "Client secrets file is missing !!"
id_ = 'contentOwner==' + id
channel_filter = 'channel=='+channel_id)
request = youtube.reports().query(ids=id_, startDate='2019-04-24', endDate='2019-04-2',dimensions='day',metrics='views',includeHistoricalChannelData=Fasle,filters=channel_filter)
response = request.execute()
通过点击它,它给了我以下的答复
{'kind': 'youtubeAnalytics#resultTable', 'columnHeaders': [{'name': 'day', 'columnType': 'DIMENSION', 'dataType': 'STRING'}, {'name': 'views', 'columnType': 'METRIC', 'dataType': 'INTEGER'}], 'rows': []}
例外回复应该是这样
{'kind': 'youtubeAnalytics#resultTable', 'columnHeaders': [{'name': 'day', 'columnType': 'DIMENSION', 'dataType': 'STRING'}, {'name': 'views', 'columnType': 'METRIC', 'dataType': 'INTEGER'}], 'rows': [['2019-08-03', 'id1', 707390, 1360, 39, 1810, 532, 3492, 1197, 1563, 4415466, 6775, 374, 13.317324220983624, 0, 0, 0, 0, 0, 0, 0, 0.02704443013522215, 0.013756007426556157, 27954, 450276, 756, 6194, 386, 2684, 146.121, 144.931, 263.398, 1.19, 205817, 287919, 0.915, 1.28], ['2019-08-03', 'id2', 786, 16, 0, 2, 0, 14, 2, 13, 3954, 28, 301, 20.51801082892648, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 2, 6, 0.239, 0.237, 0.431, 0.001, 282, 357, 1.207, 1.528], ['2019-08-04', 'id3', 702268, 1301, 31, 1796, 510, 3355, 1073, 1580, 4457715, 5936, 380, 13.586028527459515, 0, 0, 0, 0, 0, 0, 0, 0.027794493756581915, 0.013419302125240899, 26588, 450396, 739, 6044, 406, 2760, 139.188, 138.194, 251.019, 0.994, 196335, 271400, 0.925, 1.279], ['2019-08-04', 'id4', 1174, 16, 1, 8, 1, 5, 0, 12, 5481, 31, 280, 22.570541556328543, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 57, 0, 0, 0, 5, 0.259, 0.259, 0.471, 0, 386, 469, 1.004, 1.22]]}
答案 0 :(得分:0)
答案对我有很大帮助。我已经在所有范围内尝试过此操作:
["https://www.googleapis.eapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/yt-analytics.readonly",
"https://www.googleapis.com/auth/youtubepartner",
"https://www.googleapis.com/auth/yt-analytics-monetary.readonly"]
现在工作正常。