我正在尝试获取在 angular5 应用程序中工作的示例 power BI 嵌入(用户拥有数据模式)。以下是我到目前为止所做的:
- 安装了 powerbi 和 powerbi 客户端 npm 包。
- 我已经创建了一个 AAD 应用程序并授予了对 powerbi api 的所有访问权限。
下面是我的组件的代码:
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);
});
}
}
但是一切都不起作用,我在控制台中遇到以下异常: 获取https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster 403(禁止)
我正在尝试使用已登录用户的许可证访问 powerbi(用户拥有数据) 我在这里缺少什么?
最佳答案
我遇到了同样的问题。对我来说,解决方案是我使用了错误的 tokenType
。 https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics声明对于“应用程序拥有”数据,应使用 Embed
。
export enum TokenType {
Aad,
Embed
}
关于Angular5 PowerBI 嵌入不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49508532/