我正在努力学习youtube上的教程和谷歌官方开发人员的很多教程
我的代码:
import os import google.auth from googleapiclient.discovery import build from googleapiclient.errors import HttpError path_to_key = "client_secret.json" # set the environment variable os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = path_to_key def upload_video_to_youtube(path_to_video, video_title, video_description, video_tags): try: # authenticate and build the YouTube API client client = build("youtube", "v3", credentials=google.auth.default()) # define the video metadata video_metadata = { "snippet": { "title": video_title, "description": video_description, "tags": video_tags, "categoryId": 22 }, "status": { "privacyStatus": "public" } } # create the request to upload the video request = client.videos().insert( part=",".join(video_metadata.keys()), body=video_metadata, media_body=path_to_video ) # execute the request and upload the video response = None while response is None: status, response = request.next_chunk() if status: print("Uploaded %d%%." % int(status.progress() * 100)) print("Video ID: ", response["id"]) except HttpError as error: print("An error occurred while uploading the video: ", error)
我的错误是:
google.auth.exceptions.DefaultCredentialsError: The file client_secret.json does not have a valid type. Type is None, expected one of ('authorized_user', 'service_account', 'external_account', 'impersonated_service_account', 'gdch_service_account')
我不知道问题出在哪里,因为我查了我的json并且它是正确的。我有一个新的谷歌claud控制台项目
我的json:
{ "installed": { "client_id": "280376606200-a1luulq********j3fmo0qege7.apps.googleusercontent.com", "project_id": "bilionare-livestyle-shorts", "auth_uri": "https://accounts.google.com/o/oauth2/auth", "token_uri": "https://oauth2.googleapis.com/token", "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", "client_secret": "GOCSPX-2cxBjDE*********xmHHVKtJV4aS ", "redirect_uris": [ "http://localhost" ] } }