"""Script to generate Google API token.""" import os from oauth2client import client from oauth2client import file from oauth2client import tools SCOPES = [ 'https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/yt-analytics.readonly', 'https://www.googleapis.com/auth/yt-analytics-monetary.readonly' ] def genereate_google_api_token(secrets_path, token_path, application_name): """Generate token function.""" storage = file.Storage(token_path) flow = client.flow_from_clientsecrets(secrets_path, SCOPES) flow.user_agent = application_name tools.run_flow( flow, storage, flags=tools.argparser.parse_args()) with open(token_path, 'r') as token_file: print(token_file.read()) if __name__ == '__main__': genereate_google_api_token( os.getenv('GOOGLE_API_SECRETS_FILE_PATH'), os.getenv('GOOGLE_API_TOKEN_FILE_PATH'), os.getenv('GOOGLE_API_APPLICATION_NAME') )