【发布时间】:2018-03-04 00:34:06
【问题描述】:
我正在尝试将 OAuth 2.0 与 Fitbit Web API 一起使用,但我不断收到错误消息。
我得到的错误是:
{"errors":[{"errorType":"invalid_client","message":"无效的授权标头格式。在授权标头中未以正确格式提供客户端 ID。收到的授权标头 = 基本 XXXXXXXXXXXXXXXXXXXXXXX,收到客户端编码 id = XXXXXX。访问 https://dev.fitbit.com/docs/oauth2 了解有关 Fitbit Web API 授权过程的更多信息。"}],"success":false}
我已经在网上搜索了几个小时,而导致此类错误的最常见原因是“基本”拼写不正确,但我认为这里的情况并非如此,因为该错误更具体地指出了 client_id 不是以适当的格式提供。
以下是我的代码的相关部分:
#These are the secrets etc from Fitbit developer
client_id = "XXXXX"
client_secret = "XXXXXXXXXXXXXXXXXXX"
# Encode OAuthTwoClientID and ClientOrConsumerSecrets and convert from strings to bytes
b64id = base64.b64encode(client_id.encode())
b64secret = base64.b64encode(client_secret.encode())
# Pass encoded ID and Secrets to header and decode
header = {'Authorization': 'Basic ' + b64id.decode() + ":" + b64secret.decode(),
'Content-Type': 'application/x-www-form-urlencoded'}
# Start the request
req = requests.get(TokenURL,BodyURLEncoded, headers=header)
有什么想法吗?
【问题讨论】:
标签: python-3.x oauth-2.0 base64 python-requests fitbit