已配置正确权限范围仍无法通过Tapkey REST API获取所有者列表
解决Tapkey API调用401未授权问题
你的代码里Authorization请求头的格式错误,这是导致401未授权的核心原因。Tapkey API要求令牌前缀使用Bearer,而非你当前使用的access_token。
修改后的代码
import requests tapkey_api_url = "https://my.tapkey.com" tapkey_api_version = "/api/v1" tapkey_auth_server = "https://login.tapkey.com" tapkey_client_id = "xxx" #redacted tapkey_client_secret = "yyy" #redacted def get_access_token(url, client_id, client_secret): response = requests.post( url, data={"grant_type": "client_credentials", "scope": "read:owneraccounts read:owneraccount:permissions"}, auth=(client_id, client_secret), ) token_json = response.json() return token_json["access_token"] token = get_access_token(f"{tapkey_auth_server}/connect/token", tapkey_client_id, tapkey_client_secret) print(f"Received token: {token}") owners_url = f"{tapkey_api_url}{tapkey_api_version}/Owners" print(owners_url) # 修正Authorization头的前缀为Bearer response = requests.get(owners_url, headers={"Authorization": f"Bearer {token}"}) print(response) print(response.json()) # 可打印响应内容确认结果
额外检查点(若修改后仍存在问题)
- 解码JWT令牌确认实际包含的
scope是否包含read:owneraccounts - 验证服务账号已被添加为目标所有者账户的管理员,而非仅Tapkey管理门户的管理员
- 确认API端点路径
/api/v1/Owners的正确性
内容的提问来源于stack exchange,提问作者Jeroen Jacobs
相关产品推荐
相关产品推荐

