创建新报告时,我应该将什么作为报告 ID 放置在 PowerBIEmbed 中?

What do I place as the report id in the PowerBIEmbed when creating a new report?

我正在尝试使用 PowerBIEmbed React 组件来创建和设计新报告。当我编辑现有报告时一切正常,但当我创建新报告时(使用通过 TokenAccessLevel.Create 生成的嵌入令牌),我收到以下错误:

Report id is required, but it was not found. You must provide an id either as part of embed configuration or as attribute 'powerbi-report-id'.

我通过配置传入的 ID 是空 GUID ("00000000-0000-0000-0000-000000000000")。我还尝试从配置中删除 属性。

我已将权限设置为 models.Permissions.All(包括 models.Permissions.Create),所以这不是问题所在。

客户代码

const config = {
  permissions: models.Permissions.All,
  tokenType: models.TokenType.Embed,
  type: 'report',
  embedURL: generatedURL,
  accessToken: generatedToken,
  viewMode: models.ViewMode.Edit,
};

return (
  <PowerBIEmbed
    embedConfig={config}
    getEmbeddedComponent={report => this.setState({ report })}
  />
);

服务器代码

var authToken = await PowerBIAuthentication.DoAuthentication(_Config);
using var client = new PowerBIClient(new Uri(_Config.ApiUrl), authToken);
var dataSets = await client.Datasets.GetDatasetsInGroupAsync(_Config.WorkspaceId, cancellationToken);
var dataSet = dataSets.Value.First(x => x.Name == "AppProtoModel");

var embedTokenParameters = new GenerateTokenRequest(TokenAccessLevel.Create, dataSet.Id);
var embedToken = await client.Reports.GenerateTokenForCreateInGroupAsync(
  _Config.WorkspaceId, 
  embedTokenParameters, 
  cancellationToken: cancellationToken);

myDoc.PowerBISettings.EmbedToken = embedToken;
myDoc.PowerBISettings.EmbedUrl = dataSet.CreateReportEmbedURL;

return myDoc;

目前,PowerBIEmbed 组件来自 powerbi-client-react library does not support create mode embedding for Power BI Report and, it can be achieved using Power BI JS SDK

参考以下代码片段:

const embedConfiguration: IEmbedConfiguration = {
   permissions: models.Permissions.All,
   tokenType: models.TokenType.Embed,
   type: "report",
   embedUrl: createReportEmbedURL,
   accessToken: createEmbedToken,
   viewMode: models.ViewMode.Edit,
   datasetId: datasetId, 
};

const report = powerbi.createReport(reportContainer, embedConfiguration);

上面代码段中提到的createReportEmbedURL 可以使用Datasets - Get Dataset API 生成。 上面代码片段中提到的 createEmbedToken 可以使用 Embed Token - Report GenerateTokenForCreateInGroup API.

生成

注意:配置中传入的datasetId要与生成createReportEmbedURL时使用的相同。

有关详细信息,请参阅以下文档: Create and save embedded report