python - 调用 UnderArmour api 时出现 Developer Inactive 错误

标签 python api oauth-2.0 mapmyfitness

尝试发布到 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>"}'

关于python - 调用 UnderArmour api 时出现 Developer Inactive 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151820/

相关文章:

python - 帮助自定义 Jinja2 扩展

python - Google App Engine(python) 更新 db.StringListProperty 争用/并发问题

api - 通过 API 获取 Jenkins Metrics 数据

oauth-2.0 - Sakai 可以允许用户使用 OAuth2 通过 Google 登录吗?

python - 如何在PYTHON中查找段落中的总字符数(不包括空格)?

python - 是否有理由能够在 .format 中声明变量?

api - 在 OSRM 中根据路线请求更改车辆配置文件?

javascript - Node.js 跨域缺少必需的请求 header 错误

reactjs - 授权代码流如何在单页应用程序中工作?

android - 为什么我的 Android 应用程序在 Google OAuth 2.0 流程中收到请求短期授权代码的未知来源异常?