def make_client(user):
credentials = AUTHOMATIC.credentials(user.credentials)
# The token refresh will be a no-op if it's not due to expire soon.
orig_token = credentials.token
credentials.refresh(soon=TOKEN_REFRESH_SECONDS)
if credentials.token != orig_token:
user.credentials = credentials.serialize()
user.put()
# TODO - The code from here down will only work for Google clients. We
# should generalize a bit.
# The refresh here should never be used, but we add it here just so
# requests will go through if we get into a weird state.
oauth_credentials = oauth2client.client.OAuth2Credentials(
access_token=credentials.token,
client_id=credentials.consumer_key,
client_secret=credentials.consumer_secret,
refresh_token=credentials.refresh_token,
token_expiry=credentials.expiration_date,
token_uri=credentials.provider_class.access_token_url,
user_agent=USER_AGENT)
http = httplib2.Http()
http = oauth_credentials.authorize(http)
return DiscoveryDocument.build('calendar', 'v3', http=http)
评论列表
文章目录