本文整理汇总了Python中oauth2client.client.AccessTokenCredentials.new_from_json方法的典型用法代码示例。如果您正苦于以下问题:Python AccessTokenCredentials.new_from_json方法的具体用法?Python AccessTokenCredentials.new_from_json怎么用?Python AccessTokenCredentials.new_from_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client.client.AccessTokenCredentials
的用法示例。
在下文中一共展示了AccessTokenCredentials.new_from_json方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get_drive_service
# 需要导入模块: from oauth2client.client import AccessTokenCredentials [as 别名]
# 或者: from oauth2client.client.AccessTokenCredentials import new_from_json [as 别名]
def _get_drive_service(self):
credentials = AccessTokenCredentials.new_from_json(self.auth_token)
# Create an httplib2.Http object and authorize it with our credentials
http = httplib2.Http()
http = credentials.authorize(http)
# Refresh the credentials as necessary
try:
if credentials.access_token_expired:
credentials.refresh(http)
except:
# Something went wrong with automatic refresh; try manually doing it
print('Manually refreshing credentials...')
flow = OAuth2WebServerFlow(client_id=credentials.client_id,
client_secret=credentials.client_secret,
scope='https://www.googleapis.com/auth/drive',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
print('Go to this link in your browser:')
print(auth_uri)
auth_code = raw_input('Enter the auth code: ')
credentials = flow.step2_exchange(auth_code)
print('Save the following credentials in the configuration file...')
exit(credentials.to_json())
drive_service = build('drive', 'v2', http=http)
return drive_service