问题描述
我正在尝试从嵌入视图中的数据集创建新报表.但是,我不断收到此内容不可用",并且 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: 'http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103458646.jpg',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 = http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103459272.jpg" 输入你的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);
更多信息可以参考这篇博客:http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103459922.jpg此外,您还可以参考微软官方文档: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: 'http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103458646.jpg', 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 = "http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103459272.jpg" "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: http://www.51sjk.com/upload/articles/1/0/334/334170_20221025103459922.jpg 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