Youtube Data API:Python快速入门:授权URL为“未经Google验证”

问题描述 投票:0回答:2

enter image description here

授权URL作为示例python程序的输出,来自此处:https://developers.google.com/youtube/v3/docs/channels/list?apix=true带我到一个网页。它说:“此应用未经Google验证”。需要帮助。

youtube-api youtube-data-api
2个回答
0
投票

[欢迎使用,Mappy,您需要在Google Cloud Platform中创建凭据,您还可以在其中获得token as client用于预生产任务和有限的同意屏幕。准备就绪后,您的应用需要由Google验证(Auth Consent ScreenOAuth Scopes for Google)。

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

# Sample Python code for youtube.channels.list
# See instructions for running these code samples locally:
# https://developers.google.com/explorer-help/guides/code_samples#python

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.readonly"]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    request = youtube.channels().list(

    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()

终端中的最低测试对我有效。

curl \
  'https://www.googleapis.com/youtube/v3/channels?part=contentDetails&forUsername=Me%20dicen%20Dai&key=[YOUR_API_KEY]' \
  --header 'Accept: application/json' \
  --compressed


0
投票

在google的Oauth同意屏幕配置中,添加范围,如果您需要对所选范围进行验证,它将显示橙色三角形。

此错误的原因是,许多Google作用域需要您进行应用验证,然后才能与外部用户一起使用。

此外,该URL还会告诉您所请求的范围是属于敏感类别还是受限制类别

https://support.google.com/cloud/answer/9110914?hl=en

© www.soinside.com 2019 - 2024. All rights reserved.