当前位置: 首页>>代码示例>>Python>>正文


Python AccessTokenCredentials.new_from_json方法代码示例

本文整理汇总了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
开发者ID:pye2k,项目名称:motion_uploader,代码行数:32,代码来源:uploader.py


注:本文中的oauth2client.client.AccessTokenCredentials.new_from_json方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。