Skip to content

Instantly share code, notes, and snippets.

@konabe
Created August 21, 2017 16:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save konabe/361a1483ee2803ce10d3561a0b86a3f5 to your computer and use it in GitHub Desktop.
Save konabe/361a1483ee2803ce10d3561a0b86a3f5 to your computer and use it in GitHub Desktop.
import httplib2
import os
import sys
from apiclient.discovery import build
from apiclient.errors import HttpError
from oauth2client.client import flow_from_clientsecrets
from oauth2client.file import Storage
from oauth2client.tools import argparser, run_flow
CLIENT_SECRETS_FILE = "client_secret.json"
YOUTUBE_READ_WRITE_SSL_SCOPE = "https://www.googleapis.com/auth/youtube.readonly"
API_SERVICE_NAME = "youtube"
API_VERSION = "v3"
MISSING_CLIENT_SECRETS_MESSAGE = "WARNING: Please configure OAuth 2.0"
def get_authenticated_service(args):
flow = flow_from_clientsecrets(CLIENT_SECRETS_FILE, scope=YOUTUBE_READ_WRITE_SSL_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(API_SERVICE_NAME, API_VERSION,
http=credentials.authorize(httplib2.Http()))
args = argparser.parse_args()
service = get_authenticated_service(args)
results = service.channels().list(**kwargs).execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment