python - 我使用 python(django 框架)从 google api 获取请求 token ,但请求 token 总是返回空的

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

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

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)

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

仅供引用:我知道我应该将用户重定向到授权 url,但我想先看看是否设置了流程,因为即使未返回请求 token ,Google 也会提供授权 url。

最佳答案

Before you can use OAuth 2.0, you must register your application using the Google APIs Console. After you've registered, go to the API Access tab and copy the "Client ID" and "Client secret" values, which you'll need later.

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

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

关于python - 我使用 python(django 框架)从 google api 获取请求 token ,但请求 token 总是返回空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8936711/

相关文章:

oauth-2.0 - Spring OAuth2 中的身份验证类型 : How does authentication via user credentials work?

oauth-2.0 - 不记名 token 身份验证和密码更改

python - Django 模型 - 在不触及 lastmodified_at 的情况下更新属性

python - 将 hexdump(packet) 保存到 scapy 中列出

django - 将 URL 变量传递给基于类的 View

python - Django DB优化过滤器点击ip和1小时差异

asp.net-mvc-4 - 如何实现 Identity Server 3 本地化

python - 从 iOS 切换 python bool 值

python - 绑定(bind)到 wxButton 的 wxPython 弹出窗口

django - 从 Heroku 上托管的 Django 项目的子目录运行非 Django 命令?