I am working on a project to programmatically upload videos to YouTube using the YouTube Data API v3 and google-api-python-client. The code is for personal use only.
Here's how I am currently handling authentication:
# importsfrom google_auth_oauthlib.flow import InstalledAppFlowfrom googleapiclient.discovery import buildflow = InstalledAppFlow.from_client_secrets_file('client_secrets.json', scopes=['https://www.googleapis.com/auth/youtube.upload'])credentials = flow.run_local_server(port=8080)youtube = build("youtube", "v3", credentials=credentials)# code to upload the videoThe code works as expected, but the issue I am facing is that every time I run the script, it opens a browser window where I have to sign in to authenticate. This is not very convenient for me as I would like this to be an automated process.
Initially, I tried using an API key for authentication, but received a 401 error with the message:
API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See Cloud Docs on AuthenticationI have reviewed the documentation, but I am a bit confused about which authentication method would suit my needs without going through the full publishing process.
Could anyone guide me on how to persist authentication so that I don't have to manually sign in every time the script runs? Any help would be appreciated.
Thanks!