Angular5 PowerBI 嵌入不起作用

Unn*_*nie 6 powerbi powerbi-embedded angular angular5

我正在尝试获取在 angular5 应用程序中工作的示例 Power 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);
 });
}
}
Run Code Online (Sandbox Code Playgroud)

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

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

Mar*_*tin 3

我有同样的问题。对我来说,解决方案是我使用了错误的tokenType. https://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
}
Run Code Online (Sandbox Code Playgroud)