了解不同的嵌入解决方案

将 Power BI 项(如报表、仪表板和 Q&A)嵌入到应用程序中,可以集成令人惊叹的完全交互式分析,而无需从头开始构建自己的数据可视化效果和控件。 嵌入的 Power BI 分析可以呈现 应用通过自己的 Power BI 帐户拥有 的数据,或者 用户通过其 Power BI 帐户拥有 的数据。

应用程序方案

在应用程序中嵌入 Power BI 报表有两种不同的方案。

  • 为组织嵌入(也称为 用户拥有数据):应用程序允许你使用自己的 Power BI 帐户登录时集成组织中用户可访问的数据、报表、仪表板和磁贴。 在此类型的应用程序中,用户拥有嵌入的数据。
  • 为客户嵌入(也称为 应用拥有数据):应用程序显示上传到自己的 Power BI 帐户的数据、报表、仪表板或磁贴。 在此类型的应用程序中,你使用的是自己的帐户,因此应用程序拥有客户的数据。 你的客户不需要自己的 Power BI 帐户。

使用的应用程序方案决定了如何检索 访问令牌,以便访问数据和在应用程序中嵌入内容。

嵌入的内容的类型由embedUrl 参数的值指定。 若要检索特定类型的内容的嵌入 URL,请调用相应的 Power BI REST API。 例如,调用 获取报表 以检索嵌入报表的嵌入 URL。

以下部分介绍如何检索访问令牌,并为每个这些应用程序方案嵌入报表。

为组织嵌入

在此方案中,应用程序的用户使用其 Power BI 帐户登录。 这为你提供访问令牌,用于访问其数据并嵌入其报表、仪表板和磁贴。

在 embedConfiguration中,将 tokenType 设置为 TokenType.Aad。

// Get models so you can use the TokenType enum.
let models = window['powerbi-client'].models;

let embedConfiguration = {
    type: 'report',
    id: '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
    embedUrl: 'https://app.powerbi.com/reportEmbed',
    tokenType: models.TokenType.Aad,
    accessToken: 'e4...rf'
};

let reportContainer = $('#reportContainer')[0];
let report = powerbi.embed(reportContainer, embedConfiguration);

为客户嵌入

在此方案中,你将创建有权访问所有 Power BI 项的专用标识。 然后,通过调用 Power BI REST API 嵌入令牌为要嵌入的报表、仪表板或磁贴生成 嵌入令牌。 嵌入令牌后,请使用以下代码嵌入报表:

在 embedConfiguration中,将 tokenType 设置为 TokenType.Embed。

// Get models so you can use the TokenType enum.
let models = window['powerbi-client'].models;

let embedConfiguration = {
    type: 'report',
    id: '5dac7a4a-4452-46b3-99f6-a25915e0fe55',
    embedUrl: 'https://app.powerbi.com/reportEmbed',
    tokenType: models.TokenType.Embed,
    accessToken: 'h4...rf'
};

let reportContainer = $('#reportContainer')[0];
let report = powerbi.embed(reportContainer, embedConfiguration);