我正在尝试访问客户的 Google Drive 以下载他们的文件。在我自己的谷歌驱动器上测试代码时,我能够成功下载文件。但是,当我从他们那里得到 oauth 代码时,我得到了错误:
oauth2client.client.FlowExchangeError: invalid_grant
在查看了其他一些答案后,建议您确保 access_type='offline',这似乎是默认设置,我可以在生成的 url 中看到设置了此参数。听起来他们返回的代码可能仅在一个小时内有效,但是我尝试在一小时内使用它,但仍然没有运气。有关如何避免此问题的任何其他建议?
这是我一直在运行的代码:
from oauth2client import client
import webbrowser
flow = client.flow_from_clientsecrets(
'client_secrets.json',
scope='https://www.googleapis.com/auth/drive.readonly',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
webbrowser.open(auth_uri)
print auth_uri
auth_code = raw_input('Enter the auth code: ')
credentials = flow.step2_exchange(auth_code)
http_auth = credentials.authorize(httplib2.Http())
它在 flow.step2_exchange 行上出错。