Angular5 PowerBI嵌入不起作用

问题描述 投票:4回答:7

我试图在角度5应用程序中使用嵌入式示例电源BI(用户拥有数据模式)。以下是我到目前为止所做的事情:

  1. 已安装的powerbi和powerbi客户端npm包。
  2. 我创建了一个AAD应用程序并且可以访问powerbi apis。

以下是我的组件的代码:

import { Component, OnInit } from '@angular/core';
import * as pbicli from 'powerbi-client';
import {AuthenticationService} from '../authentication';
@Component({
  selector: 'app-powerbi-qna',
  templateUrl: './powerbi-qna.component.html',
  styleUrls: ['./powerbi-qna.component.scss']
})
export class PowerbiQnaComponent implements OnInit {
embedToken: string;
  constructor(private authSvc: AuthenticationService) { }

  ngOnInit() {
    // get embed tokens

    this.loadDashboard();
  }
loadDashboard() {
// Read embed application token from textbox
this.displayDashboard(this.authSvc.getCachedToken());
}
displayDashboard(token: string) {
const embedUrl = 'https://app.powerbi.com/reportEmbed?reportId=<reportid>';
const embedReportId = '<reportid>';
const config = {
    type: 'report',
    tokenType: 0,
    accessToken: token,
    embedUrl: embedUrl,
    id: embedReportId,
    permissions: 7,
    settings: {
    }
};
// Get a reference to the embedded report HTML element
const embedContainer = <HTMLElement>document.getElementById('powerBiEmbed');
const powerbi = new pbicli.service.Service(pbicli.factories.hpmFactory, pbicli.factories.wpmpFactory, pbicli.factories.routerFactory);
// Embed the report and display it within the div container.
const report = powerbi.embed(embedContainer, config);
// Report.off removes a given event handler if it exists.
report.off('loaded');
// Report.on will add an event handler which prints to Log window.
report.on('loaded', function() {
  console.log('Loaded');
});
report.on('error', function(event) {
  console.log(event.detail);
    report.off('error');
});
report.off('saved');
report.on('saved', function(event) {
    console.log(event.detail);
 });
}
}

但事情不起作用,我在控制台中得到以下异常:GET https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster 403(Forbidden)

我正在尝试使用登录用户许可证访问power bi(用户拥有数据)我在这里缺少什么?

angular angular5 powerbi powerbi-embedded
7个回答
2
投票

我有同样的问题。对我来说解决方案是我使用了错误的tokenTypehttps://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics表示,对于“应用程序拥有”数据,应使用Embed

来自https://github.com/Microsoft/powerbi-models/blob/baaaf184d4966b09094a2539a538bf10c6cb69c4/src/models.ts

export enum TokenType {
    Aad,
    Embed
}

1
投票

请参阅我的文章,其中包含在角度应用中嵌入powerbi报告的步骤。本文包含在工作区下部署报表,在Azure AD中授予所需权限,同时授予与PowerBI嵌入等相关的管理员同意的步骤.https://snkrishnan1.wordpress.com/2018/06/25/embed-power-bi-reports-in-angular-5-application/


0
投票

我有类似的问题。希望这会有所帮助。

一些PowerBI资源有组ID,有些则没有。如果省略组ID,那么你将获得403 Forbidden。

我的embedUrl看起来像这样:

embedUrl: `https://app.powerbi.com/${PbiType}Embed?${PbiType}Id=${ResourceId}` + (GroupId ? `&groupId=${GroupId}` : ''),


0
投票

@Patrick P.:您的授权标头值'EmbedToken ey ....'表示您在嵌入配置中意外使用了tokenType:Embed(1)。

经验法则:令牌的ey前缀通常表示AAD TokenType(0),H4前缀表示EmbedToken(1)。

正如@Taul所回答的那样,这通常是错误令牌的问题。其他选项在config中可能是错误的groupId和reportId。


0
投票

我遇到了同样的问题。当@RBreuer要求完整标题时,这是我的:

请求(作为CURL,从Chrome导出)

curl'https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster'-H'授权:EmbedToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSU ....'-H'来源:https://app.powerbi.com'-H'接受编码:gzip,deflate,br'-H'接受语言:en-US,en; q = 0.9'-H'RequestId:b6837253-d152-8325-08b9-227c683363d3'-H'ActivityId:b91d1b42-3d72-4cd2-8094-709af013cf83'-H'接受:application / json,text / plain,/' - H 'Referer:https://app.powerbi.com/reportEmbed?reportId=53f75214-7b5f-4264-b7ea-xxxxxxxxxx&groupId=b580bbcc-75ce-4347-bbfd-xxxxxxxxx'-H'用户代理:Mozilla / 5.0(X11; Linux x86_64)AppleWebKit / 537.36(KHTML,与Gecko一样)Ubuntu Chromium / 66.0.3359.181 Chrome / 66.0.3359.181 Safari / 537.36'-H'连接: keep-alive' - 压缩

答案是:

Request URL: https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster
Request Method: GET
Status Code: 403 Forbidden
Remote Address: 13.95.158.123:443
Referrer Policy: no-referrer-when-downgrade

我正在使用最新的powerbi-client运行Angular6

我在后端收到带有adal(python lib)的accessToken以获取prev。配置Azure应用程序,本机支持代理我的pbi-report,如PBI-Docs for App Owns Data配置中所述。

希望信息能帮助某人解决问题或者至少指向正确的方向;)


0
投票

使用以下代码将PowerBI报告嵌入到Angular应用程序中。它对我来说很完美。您需要填写accessToken,embedUrl,embedReportId。

showReport() {
    // Report's Secured Token
    let accessToken = 'Access Token';
    // Embed URL
    let embedUrl = 'Embed URL';
    // Report ID
    let embedReportId = 'Report ID';
    let config = {
      type: 'report',
      accessToken: accessToken,
      embedUrl: embedUrl,
      id: embedReportId,
      permissions: pbi.models.Permissions.All,
      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);
    var rep = powerbi.get(reportContainer);

    //Report.off removes a given event handler if it exists.
    report.off("loaded");
    // Report.on will add an event handler which prints to Log window.
    report.on("loaded", function () {
      console.log("Loaded");
    });    
  }

-2
投票

某些地区可能无法提供power bi服务。请检查您所在地区的服务可用性。其他原因可能是您应该创建本机应用程序然后尝试嵌入。

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