在GAE Python应用程序中获取Google OAuth刷新令牌

时间:2013-04-24 04:12:19

标签: python google-app-engine oauth-2.0

我使用以下代码通过交换oauth代码来获取Google刷新令牌。

access_token_uri = 'https://accounts.google.com/o/oauth2/token'
redirect_uri = selfURL + "oauth2callback?step=token"

params = urllib.urlencode({
       #'access_token_uri': access_token_uri,
        'code': code,
        'client_id': self.client_id,
        'client_secret': self.client_secret,
        'redirect_uri': redirect_uri,
        'grant_type': 'authorization_code'
    })
headers={'content-type':'application/x-www-form-urlencoded','Content-length':len(params),'Host':'accounts.google.com'}
response = urlfetch.fetch(
                              url=access_token_uri,
                              payload=params,
                              method='POST',
                              headers=headers,
                              allow_truncated=False,
                              follow_redirects=True,
                              deadline=100)

但是它发送了无效的请求响应

  

{     “错误”:“invalid_request”   }

任何帮助?

0 个答案:

没有答案