Python Youtube Api开发人员密钥

时间:2019-05-12 20:51:46

标签: python google-api youtube-api google-api-python-client

我正在运行代码为空?

哪个是对的?

1-DEVELOPER_KEY =“ AIzaSyxxxxxxxxxxxxxxxxxxx”

2-DEVELOPER_KEY =“ 779749880288-xxxxxxxxxxxxxxx.apps.googleusercontent.com”

“”“

import os

import googleapiclient.discovery

from googleapiclient.http import MediaFileUpload


def main():

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

    api_service_name = "youtube"
    api_version = "v3"
    DEVELOPER_KEY = "AIzaSyCtHy6xxxxxxxxxxxxxxxxxxxxx"

    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, developerKey=DEVELOPER_KEY)

    request = youtube.videos().insert(
        part="snippet,status",
        body={
            "snippet": {
                "categoryId": "22",
                "description": "Description of uploaded video.",
                "title": "Test video upload."
            },
            "status": {
                "privacyStatus": "private"
            }
        },

        media_body=MediaFileUpload("/Users/mac/Desktop/Projelerim/dos/video.avi")
    )
    response = request.execute()

    print(response) """

1 个答案:

答案 0 :(得分:0)

都不是。

  

videos.insert将视频上传到YouTube,并可以选择设置视频的元数据。

此方法会将视频上传到您需要用户的用户帐户。 API密钥用于访问公共数据而非私有数据。

您将需要使用Oauth2使用以下范围之一来对用户进行身份验证

enter image description here

SCOPES = ['https://www.googleapis.com/auth/youtube.upload']
DISCOVERY_URI = ('https://analyticsreporting.googleapis.com/$discovery/rest')
CLIENT_SECRETS_PATH = 'client_secrets.json' # Path to client_secrets.json file.

# Set up a Flow object to be used if we need to authenticate.
flow = client.flow_from_clientsecrets(
  CLIENT_SECRETS_PATH, scope=SCOPES,
  message=tools.message_if_missing(CLIENT_SECRETS_PATH))