Java 无法嵌入Power BI报告
在Azure portal中,我注册了一个类型为“Native”的应用程序。在Java中,我能够使用这个API调用获取访问令牌 职位 请求参数Java 无法嵌入Power BI报告,java,jquery,azure,powerbi,Java,Jquery,Azure,Powerbi,在Azure portal中,我注册了一个类型为“Native”的应用程序。在Java中,我能够使用这个API调用获取访问令牌 职位 请求参数 客户端id:azure门户上的appId 授权类型:“密码”这是硬记录的 资源:“” 用户名:电子邮件 密码:电子邮件的密码 这给了我一个accessToken和一个refreshToken。我可以使用此accessToken调用任何Power BI API。如获取所有报告、克隆报告、创建数据集等 现在我想在我的网页中嵌入一个报告,我使用jquery使用
function embedPBIReport(txtAccessToken, embedUrl, embedReportId, mode) {
// Read embed URL from textbox
var txtEmbedUrl = embedUrl;
// Read report Id from textbox
var txtEmbedReportId = embedReportId;
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// We give All permissions to demonstrate switching between View and Edit mode and saving report.
var permissions = mode == 1 ? models.Permissions.Read : models.Permissions.ReadWrite ;
var viewMode = mode == 1 ? models.ViewMode.View : models.ViewMode.Edit;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config = {
type: 'report',
tokenType: models.TokenType.Embed,
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
id: txtEmbedReportId,
permissions: permissions,
viewMode: viewMode,
settings: {
filterPaneEnabled: false,
navContentPaneEnabled: true
}
};
// Get a reference to the embedded report HTML element
var embedContainer = $('#reportContainer');
// Embed the report and display it within the div container. --> -->
var report = embedContainer.powerbi(config);
}
当我启动网页嵌入时,它会创建一个Iframe,并将powerbi图标显示为loader,然后抛出此错误
{"message":"LoadReportFailed","detailedMessage":"Get report failed","errorCode":"403","level":6,"technicalDetails":{"requestId":"f62b4819-7cd0-1c6d-1af0-a89050881a8a"}}
我在谷歌上搜索过这个问题,人们说403是由于身份验证过程不正确造成的。我在这里做错了什么?看起来您试图嵌入指定错误令牌类型的报告。在代码中,令牌类型设置为
嵌入
:
tokenType: models.TokenType.Embed
虽然您从未提到过这样的结果是生成的(例如使用)。因此,您可能正在使用初始身份验证期间获取的令牌。如果你想使用它,你应该改为Aad:
tokenType: models.TokenType.Aad
不同之处在于Azure AD令牌允许访问用户的数据、报告、仪表板和互动程序,而嵌入令牌是特定于嵌入项的。另外,嵌入令牌的生存时间(约5分钟)比AAD令牌(约1小时)短。我实际上没有使用GenerateTokenInGroup,这是我的一个错误。我正在使用嵌入令牌类型,但没有生成用于嵌入报表的特定令牌。谢谢