1

我正在使用下面的代码通过交换 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)

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

{“错误”:“无效请求”}

有什么帮助吗?

4

0 回答 0