【问题标题】:How to generate RequestToken URL for Google API如何为 Google API 生成 RequestToken URL
【发布时间】:2014-09-18 13:55:36
【问题描述】:
我正在编写 Python 2.7 桌面应用程序,它需要使用 OAuth 2.0 访问 Google 电子表格。我找到了一个用于 python here 的 Google 电子表格库,它使用 this python OAuth2.0 库。 here 描述的桌面应用程序流程告诉我,我必须首先生成 RequestToken URL,用户可以使用该 URL 来获取应用程序的授权代码。
我已经在开发者控制台中生成了客户端 ID 和客户端密码。但我不知道可以使用什么类/方法在 python 中生成 RequestToken URL。
我应该以某种方式自己构建它还是有一个 API 来做它?
【问题讨论】:
标签:
python
oauth-2.0
google-api
google-api-python-client
【解决方案1】:
我从文档 here 中发现了这一点
#!/usr/bin/env python
import oauth2client
from oauth2client.client import OAuth2WebServerFlow
flow = OAuth2WebServerFlow(client_id='your_client_id',
client_secret='your_client_secret',
scope='https://spreadsheets.google.com/feeds',
redirect_uri='urn:ietf:wg:oauth:2.0:oob')
auth_uri = flow.step1_get_authorize_url()
print auth_uri
不过,您需要自己的 client_id 和 client_secret。