Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular5 PowerBI Embed not working

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:

  1. Installed powerbi & powerbi client npm packages.
  2. I have created an AAD app and given all access to powerbi apis.

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?

like image 921
Unnie Avatar asked Mar 27 '18 09:03

Unnie


1 Answers

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
}
like image 107
Martin Avatar answered Nov 15 '22 06:11

Martin