问题描述
我正在尝试从嵌入视图中的数据集创建新报表.但是,我不断收到此内容不可用",并且 reportEmbed.min.js 在渲染时返回 403.在 app.powerbi.com 中,我可以成功创建和保存报告,但如上所述,嵌入式视图不起作用.
我完全遵循此文档:https://github.com/Microsoft/PowerBI-JavaScript/wiki/Create-Report-in-Embed-View
但是,我通过 Power BI API 调用生成我的嵌入令牌,因为此处的文档允许:https://msdn.microsoft.com/en-us/library/mt784614.aspx
这是我的服务器端 embedToken 生成代码:
const createReportEmbedTokenForCreation = ({访问令牌,组ID,数据集ID,}) =>新承诺((解决,拒绝)=> {常量 url = `https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports/GenerateToken`;常量头 = {内容类型":应用程序/x-www-form-urlencoded",授权:`Bearer ${accessToken}`,};常量形式 = {访问级别:'创建',数据集ID,允许保存为:真,};request.post({ url, form, headers }, (err, result, body) => {如果(错误)返回拒绝(错误);常量 bodyObj = JSON.parse(body);如果(bodyObj.error)返回拒绝(新错误(body));返回解析(bodyObj.token);});});
这是我的客户端嵌入代码:
const config = {accessToken: embedToken,embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed',datasetId:defaultReport.datasetId,};常量报告 = powerbi.createReport(document.getElementById('ReportEmbed'),配置,);
我是否在某些地方遗漏了一些范围?
提前致谢!
在嵌入应用程序中创建一个新报告.您必须使用 API -GenerateTokeForCreateInGroup
.
所以服务器端看起来像这样:
//生成要创建的嵌入令牌var generateTokenRequestParameters = new GenerateTokenRequest(TokenAccessLevel.创建,输入你的数据集ID",允许另存为:真);var tokenResponse = client.Reports.GenerateTokenForCreateInGroup(输入你的workspaceid", generateTokenRequestParameters);//填充嵌入变量(传递给客户端)embedToken = tokenResponse.Token;embedUrl = https://app.powerbi.com/reportEmbed?groupId=" + 输入你的workspaceid";datasetId = "输入您的工作空间ID";
<块引用>
注意:此 API 不支持行级安全性.因此,没有GenerateTokenRequest中已经定义了有效身份.
您的客户端代码将如下所示:
//读取嵌入令牌var embedToken = <% = this.embedToken %>";//读取嵌入 URLvar embedUrl = <% = this.embedUrl %>";//读取数据集 IDvar datasetId = <% = this.datasetId %>";//获取模型(模型包含枚举)var models = window['powerbi-client'].models;//嵌入配置用于描述嵌入什么以及如何嵌入//调用 powerbi.embed 时使用该对象//还可以包含过滤器等设置和选项var embedCreateConfiguration = {类型:报告",令牌类型:models.TokenType.Embed,accessToken: embedToken,嵌入网址:嵌入网址,数据集ID:数据集ID,};//将报表嵌入到 div 元素中var report = powerbi.createReport(embedDiv, embedCreateConfiguration);var saveAsParameters = {名称:新报告"};//另存为报告报告.saveAs(saveAsParameters);
更多信息可以参考这篇博客:https://addendanalytics.com/create-a-new-report-in-embed-view/.此外,您还可以参考微软官方文档:https://docs.microsoft.com/en-us/javascript/api/overview/powerbi/create-edit-report-embed-view?tabs=embed-for-your-customers
I am trying to create a new report from a dataset in an embedded view. However, I keep getting "This content isn't available" and the reportEmbed.min.js returning a 403 on render. Within app.powerbi.com I can successfully create and save reports, but as mentioned above the embedded view is not working.
I am following this documentation exactly: https://github.com/Microsoft/PowerBI-JavaScript/wiki/Create-Report-in-Embed-View
However, I am generating my embed token via a Power BI API call as documentation allows here: https://msdn.microsoft.com/en-us/library/mt784614.aspx
Here is my server-side, embedToken generation code:
const createReportEmbedTokenForCreation = ({
accessToken,
groupId,
datasetId,
}) =>
new Promise((resolve, reject) => {
const url = `https://api.powerbi.com/v1.0/myorg/groups/${groupId}/reports/GenerateToken`;
const headers = {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Bearer ${accessToken}`,
};
const form = {
accessLevel: 'Create',
datasetId,
allowSaveAs: true,
};
request.post({ url, form, headers }, (err, result, body) => {
if (err) return reject(err);
const bodyObj = JSON.parse(body);
if (bodyObj.error) return reject(new Error(body));
return resolve(bodyObj.token);
});
});
Here is my client-side embed code:
const config = {
accessToken: embedToken,
embedUrl: 'https://embedded.powerbi.com/appTokenReportEmbed',
datasetId: defaultReport.datasetId,
};
const report = powerbi.createReport(
document.getElementById('ReportEmbed'),
config,
);
Am I missing some scope some where?
Thanks in advance!
To create a new report in the embed application. You will have to use the API -GenerateTokeForCreateInGroup
.
So the server-side will look something like this:
// Generate an embed token to create
var generateTokenRequestParameters = new GenerateTokenRequest(
TokenAccessLevel.Create,
"enter your datasetid",
allowSaveAs: true
);
var tokenResponse = client.Reports.GenerateTokenForCreateInGroup("enter your workspaceid", generateTokenRequestParameters);
// Populate embed variables (to be passed client-side)
embedToken = tokenResponse.Token;
embedUrl = "https://app.powerbi.com/reportEmbed?groupId=" + "enter your workspaceid";
datasetId = "enter your workspaceid";
Note: Row-Level Security is not supported for this API. Hence, no effective identity has been defined in GenerateTokenRequest.
Your client-side code will look something like this:
// Read embed token
var embedToken = "<% = this.embedToken %>";
// Read embed URL
var embedUrl = "<% = this.embedUrl %>";
// Read dataset Id
var datasetId = "<% = this.datasetId %>";
// Get models (models contains enums)
var models = window[‘powerbi-client’].models;
// Embed configuration is used to describe what and how to embed
// This object is used when calling powerbi.embed
// It can also includes settings and options such as filters
var embedCreateConfiguration = {
type: ‘report’,
tokenType: models.TokenType.Embed,
accessToken: embedToken,
embedUrl: embedUrl,
datasetId: datasetId,
};
// Embed the report within the div element
var report = powerbi.createReport(embedDiv, embedCreateConfiguration);
var saveAsParameters = {
name: "newReport"
};
// SaveAs report
report.saveAs(saveAsParameters);
For more information, you can refer to this blog: https://addendanalytics.com/create-a-new-report-in-embed-view/. Further, you can also refer to Microsoft's official documentation: https://docs.microsoft.com/en-us/javascript/api/overview/powerbi/create-edit-report-embed-view?tabs=embed-for-your-customers
这篇关于通过 PowerBI API 在嵌入视图中创建报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!