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

发布于 2024-12-27 21:06:52 字数 594 浏览 4 评论 0原文

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

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)

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

仅供参考:我知道我应该将用户重定向到授权网址,但我想看看在我之前是否设置了流程,因为即使未返回请求令牌,Google 也会提供授权网址。

Here is sample code that I'm working with.

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)

For some reason 'flow' is always set to " " or empty instead of a request token. I have searched for days on this issue.
Can anyone tell me why I can't get a request token from google using this method?

fyi: I know that I should be redirecting the user to the authorize url, but I want to see if flow is set before I do since Google will provide the authorize url even if a request token wasn't returned.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入怼 2025-01-03 21:06:52

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

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

如果这个答案确实有助于解决您的问题,那么我必须向 SO 出价 RIP

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

If this answer actually helps with your problem then I must bid an R.I.P. to S.O.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文