尝试发布到 access_token endpoint 时收到 403“开发人员不活动”错误在 UnderArmour Connected Fitness api 中。正在使用的 client_id 处于事件状态。调用中使用的 url 是:https://api.ua.com/v7.1/oauth2/access_token/
这是获取授权码后使用python调用的片段:
import requests
access_token_url = 'https://api.ua.com/v7.1/oauth2/access_token/'
access_token_data = {'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': authorize_code}
response = requests.post(url=access_token_url, data=access_token_data)
In [24]: response
Out[24]: <Response [403]>
In [25]: response.content
Out[25]: '<h1>Developer Inactive</h1>'
其中 CLIENT_ID 和 CLIENT_SECRET 是我在开发者门户网站上注册的值。
对 api.ua.com 的所有调用都必须包含“api-key” header 值,否则,您将收到 403 Developer Inactive 错误。
这个片段展示了如何在 python 中做到这一点:
import requests
access_token_url = 'https://api.ua.com/v7.1/oauth2/access_token/'
access_token_data = {'grant_type': 'authorization_code',
'client_id': CLIENT_ID,
'client_secret': CLIENT_SECRET,
'code': authorize_code}
headers = {'api-key': CLIENT_ID}
response = requests.post(url=access_token_url, data=access_token_data, headers=headers)
In [30]: response
Out[30]: <Response [200]>
In [31]: response.content
Out[31]: '{"user_id": "<user_id>", "access_token": "<access token>", "expires_in": 2591999, "token_type": "Bearer", "scope": "read", "user_href": "/v7.1/user/<user id>/", "refresh_token": "<refresh token>"}'
我是一名优秀的程序员,十分优秀!