【发布时间】:2020-01-11 21:25:17
【问题描述】:
我从 python 脚本的 youtube 分析 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]]}
【问题讨论】:
-
频道ID还有效吗?
-
是的,它仍然有效。
-
如果我记得 YouTube 分析不会存储很长时间的数据,我认为它像 90 天。如果您没有收到任何数据,那是因为您的请求没有数据。
-
您好,感谢您的回复。我知道 youtube 将数据保留 80 天而不是 90 天。但我正在为当前月份的日期以及上个月的日期点击它。但它仍然没有给出任何回应。行和以前一样是空的。我在哪里阅读了一些内容,他们建议将其注册到新范围,即“googleapis.com/auth/youtube.readonly”。但怎么做我不知道。你有吗?
-
您好,感谢大家的支持。我尝试使用所有范围,即 ['googleapis.com/auth/yt-analytics.readonly','https://…,现在它工作正常,现在能够从分析 api 检索数据。
标签: python youtube-api youtube-analytics-api