PowerBi-Javascript报告嵌入群集详细信息403错误

问题描述 投票:2回答:2

我正在尝试在打字稿应用程序中显示power bi报告。

我已成功从AAD获得访问令牌,实际上可以通过power bi rest api使用它。我希望能够使用PowerBi-Javascript,清洁度和能够应用过滤器。但是我每次打电话给https://api.powerbi.com/powerbi/globalservice/v201606/clusterdetails时都会收到403错误,说'TokenExpired' - 即使令牌刚刚生成并且至少有效一小时也是如此。

嵌入报告的代码如下所示:

private embedReport(accessToken: string): powerBiClient.Embed {
  const element = this.getDisplayElement();
  const reportId = this.getReportId();
  const config = {
    type: 'report',
    id: reportId,
    tokenType: powerBiClient.models.TokenType.Aad,
    accessToken: accessToken
  };
  return this.powerBiService.embed(element, config);

getDisplayElement返回相应的HTMLElement,getReportId显示报告的id,powerBiClient是powerbi-javascript导入,powerBiServicepowerBiClient.service.Service的实例。

我尝试使用我拥有的报告以及组中的报告(将groupId添加到配置中)。

我该如何解决这个错误?

typescript powerbi powerbi-embedded
2个回答
0
投票

看起来您在配置中缺少embedUrl选项(请参阅文档中的this example)。这是从Power BI REST API返回的,例如在get reports API中。


0
投票

我使用Angular 7完成了如下操作。

零件:

showReport() {
 let accessToken = 'your access token’;
   // Embed URL
   let embedUrl = 'your embed URL';
   // Report ID
   let embedReportId = 'your embed report ID';
   let config = {
     type: 'report',
     pageName: 'aaa',
     name: 'Chamila',
     accessToken: accessToken,
     embedUrl: embedUrl,
     id: embedReportId,
     permissions: pbi.models.Permissions.All,
     viewMode: pbi.models.ViewMode.Edit,
     settings: {
       localeSettings: {
         language: "en",
         formatLocale: "es"
       },
     }
   };
   // Grab the reference to the div HTML element that will host the report.
   let reportContainer = <HTMLElement>document.getElementById('reportContainer');
   // Embed the report and display it within the div container.
   let powerbi = new pbi.service.Service(pbi.factories.hpmFactory, pbi.factories.wpmpFactory, pbi.factories.routerFactory);
   let report = powerbi.embed(reportContainer, config);
 }

Html:

<div id="reportContainer"></div>

替换适当的访问令牌,嵌入网址和报告ID。它对我来说很完美。

© www.soinside.com 2019 - 2024. All rights reserved.