def main(args):
storage = Storage('credentials.dat')
credentials = storage.get()
if credentials is None or credentials.invalid:
flow = flow_from_clientsecrets(
CLIENT_SECRETS, scope=SCOPES)
# run_flow will prompt the user to authorize the application's
# access to BigQuery and return the credentials.
credentials = tools.run_flow(flow, storage, args)
# Create a BigQuery client using the credentials.
bigquery_service = discovery.build(
'bigquery', 'v2', credentials=credentials)
# List all datasets in BigQuery
try:
datasets = bigquery_service.datasets()
listReply = datasets.list(projectId=args.project_id).execute()
print('Dataset list:')
pprint.pprint(listReply)
except HttpError as err:
print('Error in listDatasets:')
pprint.pprint(err.content)
except AccessTokenRefreshError:
print('Credentials have been revoked or expired, please re-run'
'the application to re-authorize')
评论列表
文章目录