与PowerBI集成:GetDashboardsInGroupAsync或GetReportsInGroupAsync返回NotFound

问题描述

我正在尝试通过PowerBI的api从PowerBI检索仪表板和报告的列表。在我的previous post中,我与api的连接存在问题。我修好了。

我正在使用Microsoft提供的PowerBI最新软件包。

enter image description here

现在,我正在尝试使用以下代码获取特定组中的仪表板或报告的列表:

if (await CreatePowerBIClient())
{
    var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(new Guid(SettingsModels.GroupId));
    var reports = await client.Reports.GetReportsInGroupAsync(new Guid(SettingsModels.GroupId));
    
    // doing something else with the list
}

我从网址中抓取groupId

enter image description here

我得到的是一个错误

Microsoft.Rest.HttpOperationException:操作返回了无效的状态码'NotFound'

enter image description here

然后,我认为这是配置错误。然后,我尝试从Microsoft文档中获取列表,然后收到仪表板或报告的列表。

enter image description here

此外,我尝试从GitHub下载Microsoft示例,但快速设置后,我遇到了类似的错误。我运行的项目是DotNetCorePaaS。

enter image description here

在Active Directory中,为Power BI服务启用了API权限。

enter image description here

获取仪表板和报告的正确方法是什么?

更新

我在PowerBI的管理门户中检查了这些值。

enter image description here

此外,我正在阅读Microsoft documentation,上的这篇文章,但是没有“工作区访问”选项。下图来自Microsoft文档:

enter image description here

这是我的(我不是管理员)

enter image description here

第二次更新

管理员将应用程序添加到PowerBI中以具有服务主体。当我尝试从Web应用程序中读取组或工作区列表时,仍然会收到错误消息。

然后我尝试运行DotNetCorePaaS,结果却遇到了同样的情况。另外,我尝试读取组列表,结果是没有组。

string groupEndPoint = $"https://api.powerbi.com/v1.0/myorg/groups";
HttpResponseMessage groupApiResponse = embedTokenClient.GetAsync(groupEndPoint).Result;
if (groupApiResponse.StatusCode == HttpStatusCode.OK)
{
    string groupContent = groupApiResponse.Content.ReadAsStringAsync().Result;
    JObject groupResponse = JsonConvert.DeserializeObject(groupContent) as JObject;
}

enter image description here

如果我从Microsoft文档中运行相同的查询,则会得到结果。

enter image description here

应用程序正在调用的URL

https://api.powerbi.com/v1.0/myorg/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b

enter image description here

并且如果我通过PowerBI检查此URL是否相似或至少WorkspaceIdReportId相同

https://app.powerbi.com/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b/ReportSection

enter image description here

然后,我尝试直接使用以下代码访问报告:

var rsp = await client.Reports.GetReportAsync(
                          new Guid("ddfb8877-932e-48d0-9f69-f96e5236504b"));

在这种情况下,我收到Forbidden错误。

enter image description here

我检查的最后一件事是PowerBI生成的报告链接。除了参数cid之外,groupId和reportId也是我期望的。

https://app.powerbi.com/groups/04639c90-832b-4d25-8852-eb5d14313f8d/reports/ddfb8877-932e-48d0-9f69-f96e5236504b?ctid=0306b564-e855-4e8a-ad57-2cf9b2b3c830

PS:我刚刚在“为Power BI注册您的应用程序”末尾注意到了此文本:

注意:此处注册的应用程序不能用作服务主体。了解如何注册服务负责人

enter image description here

但是在另一个Microsoft文档中,我可以看到以下重要消息:

如果启用服务主体与Power BI一起使用,则Azure Active Directory权限不再生效。权限通过Power BI管理门户进行管理。

此过程在Active Directory中创建了一个新应用程序。我正在使用此应用程序设置服务主体。我可以这样做还是必须创建一个新应用?

最新解决方案

在PowerBI中,我创建了一个新的工作区。有了这个,我可以设置Workspace access:在这里我可以从Active Directory中找到我的应用程序!代码正在工作!

解决方法

问题出在工作空间的允许下。我创建了一个新代码,现在代码可以正常使用了。

在帖子中,我添加了要遵循的解决方法。

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...