def auth_stored_credentials(self, client_secrets_file, scopes=[]):
"""Authorize stored credentials."""
try:
import argparse
parser = argparse.ArgumentParser(parents=[tools.argparser])
parser.add_argument('args', nargs=argparse.REMAINDER)
flags = parser.parse_args()
flags.noauth_local_webserver = True
except ImportError:
flags = None
store = Storage(self.credentials_file)
credentials = store.get()
if not credentials or credentials.invalid:
flow = client.flow_from_clientsecrets(
client_secrets_file,
scopes,
)
flow.user_agent = self.app_name
if flags:
credentials = tools.run_flow(flow, store, flags)
else: # Needed only for compatibility with Python 2.6
credentials = tools.run(flow, store)
print 'Saved credentials to ' + self.credentials_file
return credentials
评论列表
文章目录