def _GetCredentialsVia3LO(client_info, credentials_filename=None):
credential_store = _GetCredentialStore(credentials_filename,
client_info['client_id'],
client_info['scope'])
credentials = credential_store.get()
if credentials is None or credentials.invalid:
for _ in range(10):
# If authorization fails, we want to retry, rather
# than let this cascade up and get caught elsewhere.
# If users want out of the retry loop, they can ^C.
try:
flow = client.OAuth2WebServerFlow(**client_info)
flags, _ = tools.argparser.parse_known_args(
['--noauth_local_webserver'])
credentials = tools.run_flow(
flow, credential_store, flags)
break
except (SystemExit, client.FlowExchangeError) as e:
# Here SystemExit is "no credential at all", and the
# FlowExchangeError is "invalid" -- usually because
# you reused a token.
pass
except httplib2.HttpLib2Error as e:
raise ValueError(
'Communication error creating credentials:'
'{}'.format(e))
else:
credentials = None
return credentials
评论列表
文章目录