1

我尝试使用 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使用收集吗?如果不是,请建议替代选项。提前致谢。

4

1 回答 1

1

401 是因为合作伙伴中心不能仅使用来自 Azure AD 的令牌。

实际的身份验证工作流程

  1. 从 Azure AD 获取令牌。
  2. 使用该令牌从 PartnerCenter 获取访问令牌。
  3. 使用此令牌与合作伙伴中心 REST API 进行通信。

更多信息在这里

于 2017-05-04T23:51:11.790 回答