我尝试使用 partnercenter api 来获取帐单详细信息。但 API 调用返回 401 错误代码。partnercpi 上提供的详细信息是正确的,如果我将其作为订阅 API 的输入,它可以正常工作。
网址: https://api.partnercenter.microsoft.com/v1/customers/<Customer-tenant-ID>/subscriptions/<Subscription-ID>/usagerecords/resources
你能建议错误的原因吗?
参考链接:https ://msftstack.wordpress.com/2016/01/05/azure-resource-manager-authentication-with-python/
这是我的python代码。
import adal
import requests
application_secret = 'asdq23Y+tRgEspFxQDPasd'
application_id = '523129-1267b-123'
authentication_endpoint = 'https://login.microsoftonline.com/'
resource = 'https://management.core.windows.net/'
context = adal.AuthenticationContext(authentication_endpoint + tenant_id)
token_response = context.acquire_token_with_client_credentials(resource, application_id, application_secret)
access_token = token_response.get('accessToken')
endpoint = "https://api.partnercenter.microsoft.com/v1/customers/<customer tenant ID>/subscriptions/<sub-id>/usagerecords/resources"
headers = {"Authorization": 'Bearer ' + access_token}
json_output = requests.get(endpoint,headers=headers)
print json_output
输出响应:
<Response [401]>
这种方法不适合partnerapi使用收集吗?如果不是,请建议替代选项。提前致谢。