我正在尝试使用Microsoft.Azure.Management.Consumption 3.0.2 包来访问使用情况和消费数据。
但是在调用UsageDetails.List
我得到以下错误:
当前 api 版本不支持订阅范围使用。请使用 2019-10-01 之后的 api 版本
是否有支持此版本的软件包的新版本(或预计会有)?
在此期间我有什么选择?
我可以直接使用 GET 反对
https://management.azure.com/subscriptions/<subscriptionId>/providers/Microsoft.Consumption/usageDetails?api-version=2019-10-01
但还有其他选择吗?
用代码更新
请求代码:
AuthenticationResult result = GetToken();
Microsoft.Rest.TokenCredentials tokenCredentials = new
Microsoft.Rest.TokenCredentials(result.AccessToken);
ConsumptionManagementClient client = new
ConsumptionManagementClient(tokenCredentials);
client.SubscriptionId = "SubscriptionId I would like to check";
var usage = client.UsageDetails.List(); // Exception here with API Version
验证码示例:
private static AuthenticationResult GetToken()
{
string clientId = "MyappId";
string[] scopes = new string[] { "https://management.azure.com/.default" };
var app = PublicClientApplicationBuilder
.Create(clientId)
.WithRedirectUri("https://localhost")
.WithTenantId("TenantId I want to check")
.Build();
var task = app.GetAccountsAsync();
task.Wait();
var accounts = task.Result;
try
{
var task1 = app.AcquireTokenSilent(scopes, accounts.FirstOrDefault()).ExecuteAsync();
task1.Wait();
return task1.Result;
}
catch (MsalUiRequiredException)
{
var task2 = app.AcquireTokenInteractive(scopes).ExecuteAsync();
task2.Wait();
return task2.Result;
}
}