powerbi - 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);
推荐阅读
- reactjs - react-native-router-flux,如何检测路由器更改?
- vue.js - bootstrap vue toast 立即消失
- python - 在 python 中导入调试构建的 tensorflow 会导致导入错误
- javascript - 在 react 中使用 Axios 在一个 componentDidMount 中调用多个 API
- c++ - C++ 中的协议缓冲区 SerializeToString/SerializeAsString 内存管理
- algorithm - 具有权益证明共识的区块链是否有特殊节点来选择获胜者?
- html - 如何使侧边栏菜单元素居中
- javascript - 使用递归查找数组中对象值的总和
- java - 我们可以使用 Java 版本 16.0.2 运行 Detox - React native 吗?
- vba - 文件夹创建代码在 SharePoint 环境中不起作用