【问题标题】:Im using python (django framework) to gain a request token from google api, but the request token always comes back empty我使用python(django框架)从google api获取请求令牌,但请求令牌总是空的
【发布时间】:2012-02-14 17:47:14
【问题描述】:

这是我正在使用的示例代码。

def index(request):                     
flow = OAuth2WebServerFlow(
        client_id='xyz.apps.googleusercontent.com',
        client_secret='xyz',
        scope='https://www.googleapis.com/auth/plus.me',
        user_agent='sample/1.0')

callback = 'http://%s/oauth2callback' % request.META[ 'HTTP_HOST' ]
authorize_url = flow.step1_get_authorize_url(callback)

return HttpResponse(flow)

由于某种原因,“流”总是设置为“”或为空,而不是请求令牌。我已经在这个问题上搜索了几天。 谁能告诉我为什么我不能使用这种方法从谷歌获取请求令牌?

fyi:我知道我应该将用户重定向到授权 url,但我想先看看是否设置了流,因为即使没有返回请求令牌,谷歌也会提供授权 url。

【问题讨论】:

    标签: python django oauth-2.0 google-api-python-client


    【解决方案1】:

    在您可以使用 OAuth 2.0 之前,您必须使用以下方式注册您的应用程序 Google API 控制台。注册后,进入 API 访问 选项卡并复制“客户端 ID”和“客户端密码”值,您将 以后需要。

    http://code.google.com/p/google-api-python-client/wiki/OAuth2#Registering

    如果这个答案确实有助于解决您的问题,那么我必须出价 R.I.P。到 S.O.

    【讨论】:

    • 嗨,约翰,感谢您的回复。实际上我已经完成了那部分,并且 api 控制台为我提供了我使用的客户端 ID 和密码。我的具体问题是实际上获得了一个我必须坚持的请求令牌,以便稍后在我的脚本中使用它来获得访问令牌。我假设“流”应该设置为谷歌提供的请求令牌。
    猜你喜欢
    • 2013-08-03
    • 2019-03-11
    • 1970-01-01
    • 2016-06-26
    • 2012-08-05
    • 2018-12-23
    • 2019-05-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多