Uploading a video to Youtube from an AWS lambda

Viewed 117

I need to upload video to YouTube from an AWS Lambda. The Lambda will be written in Python3(.9)

I first tried locally the upload_video.py sample code provided here that I converted to Python3 I retrieved the OAUTH client_secrets.json as explained in the doc and when I launch the script it prints an URL in the console that I'm supposed to enter in the browser to retreive a validation code.

But as my code will run unattended inside a lambda, there will be no-one to use that URL.

Is it possible to upload a video to YouTube using an API Key instead ? I can't seem to find how the sample should be modified to use an API Key instead of this interactive validation.

The part of the sample code that currently deals with the authentication is below.

Thanks

from apiclient.discovery import build
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import run_flow

def get_authenticated_service(args):
  flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE,
    scope=YOUTUBE_UPLOAD_SCOPE,
    message=MISSING_CLIENT_SECRETS_MESSAGE)

  storage = Storage("%s-oauth2.json" % sys.argv[0])
  credentials = storage.get()

  if credentials is None or credentials.invalid:
    credentials = run_flow(flow, storage, args)

  return build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
    http=credentials.authorize(httplib2.Http()))
0 Answers
Related