YouTube Analytics返回“请求”不需要认证凭证。 &quot

发布于 2025-02-12 08:31:21 字数 2186 浏览 1 评论 0 原文

我想使用YouTube Analytics抓取视频的一些数据。

部分代码是

scopes = [
        'https://www.googleapis.com/auth/yt-analytics.readonly',
        'https://www.googleapis.com/auth/youtube.download',
        'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
        'https://www.googleapis.com/auth/youtube.readonly',
        'https://www.googleapis.com/auth/youtube',
        'https://www.googleapis.com/auth/youtube.force-ssl',
        'https://www.googleapis.com/auth/youtubepartner',
        'https://www.googleapis.com/auth/youtube.upload',
        'https://www.googleapis.com/auth/youtube.channel-memberships.creator',
        'https://www.googleapis.com/auth/youtube.third-party-link.creator',
        ]

client_secrets_file = 'client_secret_xxxxxxx.apps.googleusercontent.com.json'

os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build('youtubeAnalytics', 'v2', credentials = credentials)

def main_data(video_id):
    request_analytics = youtube_analytics.reports().query(
        startDate = '%d-%02d-01' % (year, month),
        endDate = '%d-%02d-%d' % (year, month, day),
        ids = 'video==%s' % video_id,
        dimensions = 'day', 
        metrics = 'views',
    )
    response = request_analytics.execute()['rows']

返回

googleapiclient.errors.httperror:< httperror 500在请求 https://youtubeanalytics.googleapis.com/v2/reports?startdate=2022-06-06-06-01&Enddate = 2022-06-30& ids =视频%3D%3DJ1NPNTRO9VY& dimensions = Day& metrics = views& alt = json 返回的“发生了内部错误。”。详细信息:“ [{'消息':'发生了内部错误。','域':'global','原因':'internationError'}]”>

然后我去了网站,它给出的错误回复是

请求缺少所需的身份验证凭据。预期的OAuth 2访问令牌,登录cookie或其他有效的身份验证凭据。

我可能做错了什么部分?

I want to use YouTube Analytics to crawl my video's some data.

partial code is

scopes = [
        'https://www.googleapis.com/auth/yt-analytics.readonly',
        'https://www.googleapis.com/auth/youtube.download',
        'https://www.googleapis.com/auth/yt-analytics-monetary.readonly',
        'https://www.googleapis.com/auth/youtube.readonly',
        'https://www.googleapis.com/auth/youtube',
        'https://www.googleapis.com/auth/youtube.force-ssl',
        'https://www.googleapis.com/auth/youtubepartner',
        'https://www.googleapis.com/auth/youtube.upload',
        'https://www.googleapis.com/auth/youtube.channel-memberships.creator',
        'https://www.googleapis.com/auth/youtube.third-party-link.creator',
        ]

client_secrets_file = 'client_secret_xxxxxxx.apps.googleusercontent.com.json'

os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(client_secrets_file, scopes)
credentials = flow.run_console()
youtube_analytics = googleapiclient.discovery.build('youtubeAnalytics', 'v2', credentials = credentials)

def main_data(video_id):
    request_analytics = youtube_analytics.reports().query(
        startDate = '%d-%02d-01' % (year, month),
        endDate = '%d-%02d-%d' % (year, month, day),
        ids = 'video==%s' % video_id,
        dimensions = 'day', 
        metrics = 'views',
    )
    response = request_analytics.execute()['rows']

It returns

googleapiclient.errors.HttpError: <HttpError 500 when requesting https://youtubeanalytics.googleapis.com/v2/reports?startDate=2022-06-01&endDate=2022-06-30&ids=video%3D%3Dj1npnTro9vY&dimensions=day&metrics=views&alt=json returned "An internal error has occurred.". Details: "[{'message': 'An internal error has occurred.', 'domain': 'global', 'reason': 'internalError'}]">

Then I went to the website and the error response it gave was

Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential.

What part might I be doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文