我想从朋友的 YouTube 频道检索获利数据。我使用下面的 python 代码从他那里获取身份验证凭据,然后将其保存到 JSON 文件中。在此过程中,他必须单击链接并将密钥发送给我。我想通过保存凭据数据来避免这种情况。我想我已经做到了,但是现在我该如何加载它呢?
import json
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
SCOPES = ['https://www.googleapis.com/auth/yt-analytics.readonly', 'https://www.googleapis.com/auth/yt-analytics-monetary.readonly']
API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE = 'client_secret_dota2rapier_youtube_analytics_api.json'
CLIENT_CREDENTIALS_FILE = 'credentials.json'
root = 'C:\\test\\'
os.chdir(root)
def get_service():
flow = InstalledAppFlow.from_client_secrets_file(CLIENT_SECRETS_FILE, SCOPES)
credentials = flow.run_console()
#SAVING CREDENTIALS DATA
creds_data = {
'token': credentials.token,
'refresh_token': credentials.refresh_token,
'token_uri': credentials.token_uri,
'client_id': credentials.client_id,
'client_secret': credentials.client_secret,
'scopes': credentials.scopes
}
save = True
if …Run Code Online (Sandbox Code Playgroud) 我想从 Youtube Music 中提取播放列表数据,以及与所述播放列表中的歌曲相关的元数据。这可以通过 Youtube Data V3 API 或 YouTube Analytics API 实现吗?
如果是这样,我在哪里可以找到有关调用和可用元数据的文档;我在 YouTube 数据 API 页面上找不到我需要的内容。我目前在参考文档中引用 PlaylistItems 和 Playlists,但似乎适用于视频。这是特意设计的吗?因为您可以在 YouTube Music 中在视频和音频之间切换?
如果可能的话有官方的 Rust Crate 吗?
预先感谢您的帮助。
youtube-api youtube-analytics youtube-data-api youtube-analytics-api
我叫下面的终点
https://youtubeanalytics.googleapis.com/v2/reports?
直到昨天,该API仍能正常工作。
我链接了一个新的YouTube帐户,以使用API提取数据,但出现403禁止错误。
我有2个accessTokens,其中一个在2周前链接了,它工作正常。但是新的accessToken抛出403禁止错误。
我也检查了范围。获取新闻accessToken时是相同的。
我该如何解决?
我正在开发一个使用 YouTube 分析 API 提取 YouTube 指标的应用程序。这是我第一次使用 google auth flow 来验证我的应用程序,以便它可以默默地提取报告。
我按照下面的谷歌发布的文章来解决同样的问题: https ://developers.google.com/youtube/reporting/guides/authorization/server-side-web-apps
在阅读本文时,我无法弄清楚如何将用户重定向到 auth_uri 并获取 auth_code。
下面是我迄今为止为身份验证流程编写的代码:
API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE = 'C:/Users/Tushar/Documents/Serato_Video_Intelligence/client_secret_youtube.json'
def get_service():
global auth_code
global auth_uri
flow = client.flow_from_clientsecrets(
CLIENT_SECRETS_FILE,
scope='https://www.googleapis.com/auth/yt-analytics.readonly',
redirect_uri = "http://localhost:8080")
flow.params['access_type'] = 'offline'
flow.params['include_granted_scopes'] = True
auth_uri = flow.step1_get_authorize_url()
credentials = flow.step2_exchange(auth_code)
http_auth = credentials.authorize(httplib2.Http())
return build(API_SERVICE_NAME, API_VERSION, http=http_auth)
def execute_api_request(client_library_function, **kwargs):
response = client_library_function(
**kwargs
).execute()
if __name__ == '__main__':
# Disable OAuthlib's HTTPs verification when running …Run Code Online (Sandbox Code Playgroud) 我想获取我的 YouTube 频道中每个视频(或大约 10 个最新视频)的指标(例如获得的点赞数、观看次数和订阅者数量),我该如何正确操作?
我正在使用来自 的此类 API 调用Youtube Analytics API,但事实证明它返回所有视频的总观看次数和总点赞数,而不是每个视频的单独值。
`https://youtubeanalytics.googleapis.com/v2/reports?metrics=views,likes,subscribersGained&ids=channel==MINE&startDate=2014-07-03&endDate=2020-06-01&&key=${apiKey}&access_token=${token}`
Run Code Online (Sandbox Code Playgroud)
我阅读了 YouTube Analytics API 的文档,但在那里找不到此信息。
我目前正在编写一个 python 脚本,用于从 YouTube Analytics API 中提取信息以获取单独的 YouTube 频道列表。例如,输出是统计上个月每个 YouTube 频道的视频观看次数。
我最初的想法是要求每个 YouTube 帐户所有者在其 console.cloud.google 中创建一个 YouTube Analytics 应用程序,创建一个项目,启用 youTube Analytics API,生成一个 API 密钥并指定 YouTube Analytics 需要它API。
我正在使用一个帐户进行测试,如果我尝试使用通过上述过程生成的 API 密钥运行脚本并进行身份验证,如下所示:
def get_service():
return build('youtubeAnalytics', 'v2', developerKey=API_KEY)
Run Code Online (Sandbox Code Playgroud)
它失败了HttpError 401 Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
我不确定我在创建 API 密钥时是否做错了什么,或者 YouTube Analytics API 是否需要Oauth2 身份验证。如果是后者,那么我很惊讶谷歌控制台允许您一路生成 API 密钥并指定它们是 YouTube Analytics API 所需要的,结果却发现您无法使用它。
所以我的问题是:我是否必须使用 Oauth2 for YouTube Analytics …
youtube youtube-api google-authentication youtube-analytics youtube-analytics-api