Database Reference
In-Depth Information
'''Generates user credentials.
Will prompt the user to authorize the client when
run the first time.
Saves the credentials in ˜/bigquery_credentials.dat.
'''
flow =
flow_from_clientsecrets('client_secrets.json',
scope=BIGQUERY_SCOPE)
storage = Storage(os.path.expanduser('˜/
bigquery_credentials.dat'))
credentials = storage.get()
if credentials is None or credentials.invalid:
credentials = run(flow, storage)
else:
# Make sure we have an up-to-date copy of the
creds.
credentials.refresh(httplib2.Http())
return credentials
def get_service_acct_creds(service_acct, key_file):
'''Generate service account credentials using the
given key file.
service_acct: service account ID.
key_file: path to file containing private key.
'''
with open (key_file, 'rb') as f:
key = f.read()
creds = SignedJwtAssertionCredentials(
service_acct,
key,
BIGQUERY_SCOPE)
return creds.refresh(httlib2.Http())
def print_creds(credentials):
'''Prints the authorization header to use in HTTP
requests.'''
cred_dict = json.loads(credentials.to_json())
if 'access_token' in cred_dict:
print 'Authorization: Bearer %s' %
(cred_dict['access_token'],)
Search WWH ::




Custom Search