【问题标题】:Google Drive SDK Python Quickstart SampleGoogle Drive SDK Python 快速入门示例
【发布时间】:2015-01-05 23:20:06
【问题描述】:
【问题讨论】:
标签:
python
google-drive-api
【解决方案1】:
问题其实很简单。API 只需要知道如何处理凭据。您会看到已安装的应用程序和 Web 应用程序以不同方式处理它。对于 Web 应用程序,授权会将用户重定向到另一个页面。对于已安装的应用程序,您可能希望获得一个密钥。
因此,如果您使用的是已安装的应用程序,请更改以下代码行。
from oauth2client.client import flow_from_clientsecrets
path_to_json="client_secrets.json" # download from https://code.google.com/apis/console/
AUTH_SCOPE 'https://www.googleapis.com/auth/drive'
#redirect_uri also provided in api console.The other URI mentioned there is for web applications.
flow = flow_from_clientsecrets(Path_to_JSON,AUTH_SCOPE,redirect_uri="urn:ietf:wg:oauth:2.0:oob")
`
【解决方案2】:
我遇到了同样的问题。我的解决方案是在代码中添加 redirect_uri="urn:ietf:wg:oauth:2.0:oob"。
#Before
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE)
#After
flow = OAuth2WebServerFlow(CLIENT_ID, CLIENT_SECRET, OAUTH_SCOPE, redirect_uri="urn:ietf:wg:oauth:2.0:oob")