简体   繁体   English

Angular5 PowerBI 嵌入不起作用

[英]Angular5 PowerBI Embed not working

I am trying to get a sample power BI embed (user owns data mode) working in an angular5 application.我正在尝试获取在 angular5 应用程序中工作的示例 Power BI 嵌入(用户拥有数据模式)。 Below is what I have done so far:以下是我到目前为止所做的:

  1. Installed powerbi & powerbi client npm packages.已安装 powerbi 和 powerbi 客户端 npm 包。
  2. I have created an AAD app and given all access to powerbi apis.我创建了一个 AAD 应用程序并授予了对 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)但事情不正常,我在控制台中得到以下异常: 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?我正在尝试使用登录用户的许可证(用户拥有数据)访问 powerbi 我在这里缺少什么?

I had the same problem.我有同样的问题。 For me the solution was that I was using the wrong tokenType .对我来说,解决方案是我使用了错误的tokenType https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics states that for "Application owned" data Embed should be used. https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embedding-Basics指出,对于“应用程序拥有的”数据,应使用Embed

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

export enum TokenType {
    Aad,
    Embed
}

Please refer my article which contains the steps to embed powerbi reports in angular application.请参阅我的文章,其中包含在 angular 应用程序中嵌入 powerbi 报告的步骤。 This article contains the steps to deploy the report under a workspace, grant the required permissions in Azure AD, also granting the admin-consent related to PowerBI embedded etc. https://snkrishnan1.wordpress.com/2018/06/25/embed-power-bi-reports-in-angular-5-application/本文包含在工作区下部署报告的步骤,在 Azure AD 中授予所需的权限,还授予与 PowerBI 嵌入式等相关的管理员同意。 https://snkrishnan1.wordpress.com/2018/06/25/embed -power-bi-reports-in-angular-5-application/

I had similar problems.我有类似的问题。 Hopefully this helps.希望这会有所帮助。

Some PowerBI resources have group ids and some don't.某些 PowerBI 资源具有组 ID,有些则没有。 If you omit the group id then you'll get a 403 Forbidden.如果您省略组 ID,则会收到 403 Forbidden。

My embedUrl looks like this:我的 embedUrl 看起来像这样:

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

I am running into the same problem.我遇到了同样的问题。 As @RBreuer asked for the full header, here are mine:由于@RBreuer 要求提供完整的标题,这里是我的:

Request (as CURL, exported from Chrome)请求(作为 CURL,从 Chrome 导出)

curl ' https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster ' -H 'Authorization: EmbedToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSU....' -H 'Origin: https://app.powerbi.com ' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.9' -H 'RequestId: b6837253-d152-8325-08b9-227c683363d3' -H 'ActivityId: b91d1b42-3d72-4cd2-8094-709af013cf83' -H 'Accept: application/json, text/plain, / ' -H 'Referer: https://app.powerbi.com/reportEmbed?reportId=53f75214-7b5f-4264-b7ea-xxxxxxxxxx&groupId=b580bbcc-75ce-4347-bbfd-xxxxxxxxx ' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/66.0.3359.181 Chrome/66.0.3359.181 Safari/537.36' -H 'Connection: keep-alive' --compressed curl ' https://wabi-west-europe-redirect.analysis.windows.net/metadata/cluster ' -H '授权:EmbedToken eyJ0eXAiOiJKV1QiLCJhbGciOiJSU ....' -H '来源: https ://app.powerbi.com ' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: 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-426 -b7ea-xxxxxxxxxx&groupId=b580bbcc-75ce-4347-bbfd-xxxxxxxxx ' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/6596.0.0. 3359.181 Safari/537.36'-H'连接:保持活动'--压缩

Answer is:答案是:

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

I am running Angular6 with latest powerbi-client.我正在使用最新的 powerbi-client 运行Angular6

I receive the accessToken with adal (python lib) in my backend for a prev.我在后端收到带有adal (python lib) 的adal用于上一个。 configured Azure Application with native support proxying my pbi-report as described in the PBI-Docs for App Owns Data configuration.如 PBI-Docs for App Owns Data 配置中所述,配置了具有本机支持代理我的 pbi-report 的 Azure 应用程序。

Hope that information help someone to solve the problem or at least point into the right direction ;)希望这些信息可以帮助某人解决问题或至少指出正确的方向;)

@Patrick P. : Your Authorization header value of 'EmbedToken ey....' suggests you're accidentally using tokenType: Embed (1) in your embed config. @Patrick P. :您的 'EmbedToken ey....' 的 Authorization 标头值表明您不小心在嵌入配置中使用了 tokenType: Embed (1)。

Rule of thumb: ey prefix of the token usually suggests AAD TokenType (0), H4 prefix suggests EmbedToken (1).经验法则:令牌的 ey 前缀通常表示 AAD TokenType (0),H4 前缀表示 EmbedToken (1)。

As @Taul answered too, this is usually the problem with wrong tokens.正如@Taul 也回答的那样,这通常是错误令牌的问题。 Other options can be wrong groupId & reportId in config.其他选项可能是配置中的 groupId 和 reportId 错误。

Use the following code to embed your PowerBI report into Angular application.使用以下代码将 PowerBI 报告嵌入到 Angular 应用程序中。 It works perfectly for me.它非常适合我。 You need to fill accessToken, embedUrl, embedReportId.需要填写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");
    });    
  }

You can try this code:你可以试试这个代码:

showReports() {
  const config = <IEmbedConfigurationBase><any>{ // add this type of object  <IEmbedConfigurationBase><any>
type: 'report',
uniqueId: 'your-report-id ',
id: 'your-report-id ',
tokenType: 'Embed Token',
settings: {
  navContentPaneEnabled: false,
  filterPaneEnabled: false
},
embedUrl: 'your-embed url',
accessToken: 'your-access-token'
};

 const reportsContainer = <HTMLElement>document.getElementById(
     'reportsContainer'
    );

const powerbi = new pbi.service.Service(
   pbi.factories.hpmFactory,
   pbi.factories.wpmpFactory,
   pbi.factories.routerFactory
 );
const report = powerbi.embed(
  reportsContainer,
  config
);
} 

For more refernces - Interface IEmbedConfigurationBase更多参考 - 接口 IEmbedConfigurationBase

Nodejs POC to generate accessToken Nodejs POC 生成accessToken

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM