【发布时间】:2013-11-21 08:02:28
【问题描述】:
我正在为我的 GDrive 文件夹创建备份脚本。每次运行我都需要向 Google 确认 该脚本可以访问 GDrive。但是,在第一次运行后,验证码应该被保存。在这篇文章中,他们提到了一个带有 Web 服务器的解决方案 (Fulfilling Google Drive API OAuth2.0 Procedure w/o needing to find a verification code) - 但我正在寻找一个没有 Web 服务器的简单备份脚本的解决方案。
- 是否有一个类可以代替
OAuth2WebServerFlow使用现有的验证码来检索正确的凭据?有没有办法跳过step1_get_authorize_url()?或者我应该为此直接使用oauth2?
我的代码
flow = OAuth2WebServerFlow(self.CLIENT_ID, self.CLIENT_SECRET, OAUTH_SCOPE, REDIRECT_URI, offline=True)
authorize_url = flow.step1_get_authorize_url()
print 'Go to the following link in your browser: ' + authorize_url
print
code = raw_input('Enter verification code: ').strip()
credentials = flow.step2_exchange(code)
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
【问题讨论】:
标签: python google-api google-api-python-client