gpt4 book ai didi

google-apis-explorer - YouTube 分析 API 行为空

转载 作者:行者123 更新时间:2023-12-01 19:37:31 25 4
gpt4 key购买 nike

我知道这个问题以前有人回答过,但我似乎遇到了不同的问题。直到几天前,我对 YouTube 的查询都没有问题。然而,现在,每次我查询任何视频的数据时,实际视频数据的行都会作为一个空数组返回。

这是我的完整代码:

# -*- coding: utf-8 -*-

import os
import google.oauth2.credentials
import google_auth_oauthlib.flow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
from google_auth_oauthlib.flow import InstalledAppFlow
import pandas as pd
import csv


SCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly']

API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE = 'CLIENT_SECRET_FILE.json'

def get_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_console()
#builds api-specific service
return build(API_SERVICE_NAME, API_VERSION, credentials = credentials)

def execute_api_request(client_library_function, **kwargs):
response = client_library_function(
**kwargs
).execute()

print(response)

columnHeaders = []

# create a CSV output for video list
csvFile = open('video_result.csv','w')
csvWriter = csv.writer(csvFile)
csvWriter.writerow(["views","comments","likes","estimatedMinutesWatched","averageViewDuration"])


if __name__ == '__main__':
# Disable OAuthlib's HTTPs verification when running locally.
# *DO NOT* leave this option enabled when running in production.
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

youtubeAnalytics = get_service()

execute_api_request(
youtubeAnalytics.reports().query,
ids='channel==UCU_N4jDOub9J8splDAPiMWA',

#needs to be of form YYYY-MM-DD
startDate='2018-01-01',
endDate='2018-05-01',
metrics='views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration',
dimensions='day',
filters='video==ZeY6BKqIZGk,YKFWUX9w4eY,bDPdrWS-YUc'
)

最佳答案

enter image description here

你可以在Reports: Query中看到您需要使用新范围的首页:

https://www.googleapis.com/auth/youtube.readonly

代替旧的:

https://www.googleapis.com/auth/yt-analytics.readonly 

更改范围后,执行重新认证(删除旧凭据)以使新范围生效。

这在 this forum 中也得到证实.

关于google-apis-explorer - YouTube 分析 API 行为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50647423/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com