尝试使用 python 刷新令牌时获取“unsupported_grant_type”
你好,
我一直在尝试使用我拥有的现有刷新令牌获取新的访问令牌和刷新令牌。我正在关注网站https://developer.xero.com/documentation/oauth2/auth-flow上所述的文档,但我一直收到错误消息“unsupported_grant_type”,尽管我确实定义了grant_type = refresh_token。这是我的代码,任何帮助将不胜感激。
import json
from base64 import b64encode
client_id = xxx
client_secret = xxx
RefreshToken = xxx
b64_id_secret = b64encode(client_id + ':' + client_secret)
def XeroRefreshToken(refresh_token):
token_refresh_url = 'https://identity.xero.com/connect/token'
response = requests.post(token_refresh_url,
headers = {
'Authorization' : 'Basic ' + b64_id_secret,
'Content-Type': 'application/x-www-form-urlencoded'
},
data = {
'grant_type' : 'refresh_token',
'refresh_token' : refresh_token
})
json_response = response.json()
print(json_response)
new_refresh_token = json_response['refresh_token']
XeroRefreshToken(RefreshToken)