我在使用 powerbi api 调用授权任务时遇到了一些问题。它在 .It 处抛出AggregateException异常。Authorize().Wait();我也用谷歌搜索了它,但无法找到任何解决方案。任何帮助,将不胜感激。这是我的Page_Load函数代码
protected void Page_Load(object sender, EventArgs e)
{
credential = new UserCredential(Username, Password);
Authorize().Wait();
using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
{
EmbedToken embedToken = client.Reports.GenerateTokenInGroup(<groupId>, <reportId>, new GenerateTokenRequest(accessLevel: "View", datasetId:<datasetId>));
Report report = client.Reports.GetReportInGroup(<groupId>,<reportId> );
System.Diagnostics.Debug.WriteLine("This is embed token");
System.Diagnostics.Debug.WriteLine(embedToken);
System.Diagnostics.Debug.WriteLine("this is embed url");
System.Diagnostics.Debug.WriteLine(report.EmbedUrl);
}
}
在这个函数中,我正在提取嵌入令牌和嵌入 url 并在输出窗口中打印出来,下面是授权函数代码
private static Task Authorize()
{
return Task.Run(async () =>
{
authenticationResult = null;
tokenCredentials = null;
var authenticationContext = new AuthenticationContext("https://login.windows.net/common/oauth2/authorize/");
authenticationResult = await authenticationContext.AcquireTokenAsync(ResourceUrl, clientId, credential);
if (authenticationResult != null)
{
tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
}
});
}
动漫人物
相关分类