微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PowerBIClient 没有任何价值

如何解决PowerBIClient 没有任何价值

我正在尝试使用 powerbi SDk 读取 powerbi 报告。我得到了正确的访问令牌(在邮递员中测试)。为 TokenCredentials 传递相同的访问令牌。但在 _powerBIClient 中没有得到任何值。它没有价值。我正在使用以下代码

var functionCred = new Microsoft.IdentityModel.Clients.ActiveDirectory.ClientCredential(_configuration[BotConfigurationEnum.FunctionClientId.GetDescription()],_configuration[BotConfigurationEnum.FunctionClientSecret.GetDescription()]);

var userAssertion = (!string.IsNullOrWhiteSpace(token)) ? new Microsoft.IdentityModel.Clients.ActiveDirectory.UserAssertion(token,"urn:ietf:params:oauth:grant-type:jwt-bearer") : null;

var context = new AuthenticationContext("https://login.microsoftonline.com/{tenentid}");
var res = await context.AcquiretokenAsync("https://analysis.windows.net/powerbi/api",functionCred,userAssertion);

var tokenCredentials = new TokenCredentials(res.Accesstoken,"Bearer");

var _powerBIClient = new PowerBIClient(new Uri("https://api.powerbi.com/"),tokenCredentials);
var pbiReport = _powerBIClient.Reports.GetReport(reportId);

解决方法

我的代码有一些小的更正。我已经删除了新 Uri 中的“/”并且它起作用了。我知道这很傻..

 var _powerBIClient = new PowerBIClient(new Uri("https://api.powerbi.com"),tokenCredentials);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。