首页 > 解决方案 > 从 youtube-analytic-api 获取空行响应

问题描述

我从 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]]}

标签: pythonyoutube-apiyoutube-analytics-api

解决方案


答案对我帮助很大。我已经尝试过所有范围:

["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"]

现在它工作正常。


推荐阅读