I am trying to get a sample power BI embed (user owns data mode) working in an angular5 application. Below is what I have done so far:
Below is the code of my component:
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);
});
}
}
But things are not working and I get below exception in console: GET https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster 403 (Forbidden)
I am trying to access the powerbi using the loggedin user's license (User owns data) What am I missing here?
I had the same problem. For me the solution was that I was using the wrong tokenType
. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics states that for "Application owned" data Embed
should be used.
From https://github.com/Microsoft/powerbi-models/blob/baaaf184d4966b09094a2539a538bf10c6cb69c4/src/models.ts:
export enum TokenType {
Aad,
Embed
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With