Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

googleapiclient.errors.UnknownApiNameOrVersion in python file

$
0
0

I want to upload a video on YouTube that is not working. I do not know why

my code:

import google.authfrom googleapiclient.discovery import buildfrom googleapiclient.errors import HttpErrordef upload_video_to_youtube(video_file, title, description, tags):    try:        # Authenticate and build the YouTube API client        client_secrets_file = "client_secret.json"        scopes = ["https://www.googleapis.com/auth/youtube.upload"]        credentials = google.auth.default(scopes=scopes)        youtube = build(client_secrets_file,"youtube", "v3", credentials=credentials)        # Define the video metadata        request_body = {"snippet": {"title": title,"description": description,"tags": tags,"categoryId": 22            },"status": {"privacyStatus": "private"            }        }        # Upload the video        with open(video_file, "rb") as video:            media = {"body": video}            response = youtube.videos().insert(                part=",".join(request_body.keys()),                body=request_body,                media_body=googleapiclient.http.MediaFileUpload(                    video_file, chunksize=1024 * 1024, resumable=True                ),            ).execute()            print(f"Video uploaded with ID: {response['id']}")    except HttpError as error:        print(f"An error occured while uploading the video: {error}")

error:

Traceback (most recent call last):   File"c:\Users\Lukas\Dokumenty\python_scripts\Billionarelivestyle\main.py", line 142, in <module>    upload_video_to_youtube("video.mp4","test","test description","test")   File"c:\Users\Lukas\Dokumenty\python_scripts\Billionarelivestyle\main.py", line 90, in upload_video_to_youtube    credentials = google.auth.default(scopes=scopes)   File "C:\Users\Lukas\Dokumenty\python_scripts\Billionarelivestyle\env\youtube\lib\site-packages\google\auth\_default.py", line616, in default    raise exceptions.DefaultCredentialsError(_HELP_MESSAGE) google.auth.exceptions.DefaultCredentialsError: Could notautomatically determine credentials. Please setGOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials andre-run the application. For more information, please seehttps://cloud.google.com/docs/authentication/getting-started

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>