Skip to main content
 首页 » 编程设计

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

2025年05月04日32grandyang

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

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.