pygsheet.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:PyGsheet 作者: betomark 项目源码 文件源码
def get_credentials(self, cred_file='client_secret.json'):
        import os
        from oauth2client.file import Storage
        from oauth2client import client
        home_dir = os.path.expanduser('~')
        credential_dir = os.path.join(home_dir, '.credentials')
        if not os.path.exists(credential_dir):
            os.makedirs(credential_dir)
        credential_path = os.path.join(credential_dir, 'python-quickstart.json')
        store = Storage(credential_path)
        credentials = store.get()
        if not credentials or credentials.invalid:
            flow = client.flow_from_clientsecrets(cred_file, scope=['https://www.googleapis.com/auth/spreadsheets', 'https://www.googleapis.com/auth/drive'])
            flow.user_agent = self.app_name
            try:
                credentials = tools.run_flow(flow, store, self.flags)
            except:  # Needed only for compatibility with Python 2.6
                try:
                    credentials = tools.run_flow(flow, store)
                except:
                    credentials = tools.run(flow, store)
            print('Storing credentials to ' + credential_path)
        return credentials
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号