我正在尝试通过授权令牌从业务中心获取客户列表。当我通过获取客户列表时它返回令牌,它抛出错误。
<块引用>{"error":{"code":"Authentication_InvalidCredentials","message":"服务器拒绝了客户端凭据。CorrelationId:ec8e4ab3-ae04-4454-9038-395ff74aeed8。"}}
为此,我尝试了以下代码。
ClientCredential clientCredential = new ClientCredential("xxx", "xxx");
var authenticationContext = new AuthenticationContext("https://login.microsoftonline.com/6fed243c-78g7-405a-8g78-xxxxx", true);//tried with URL=> https://login.windows.net/6fed243c-78g7-405a-8g78-xxxxx also
AuthenticationResult authenticationResult2 = authenticationContext.AcquireTokenAsync("https://api.businesscentral.dynamics.com", clientCredential).GetAwaiter().GetResult();
var nav = new NAV.NAV(new Uri("https://api.businesscentral.dynamics.com/v2.0/6fed243c-78g7-405a-8g78-xxxxx/BC18Sandbox/ODataV4/Company('CRONUS USA, Inc.')"));
nav.BuildingRequest += (sender, eventArgs) => eventArgs.Headers.Add("Authorization", "Bearer " + authenticationResult2.AccessToken);
var customerList = nav.Customer.ToArray();
你能告诉我为什么令牌对我不起作用。
答案 0 :(得分:0)
您正在调用 OData Web 服务,这与调用 API 不同。它们是暴露一些相同数据的两种不同事物。
尝试调用 API,例如:
https://api.businesscentral.dynamics.com/v2.0/<your tenant domain>/<environment name>/api/v2.0
您可以找到简短的说明 here。