在Azure门户中,我注册了一个“本地”类型的应用程序。在Java中,我可以使用此API调用获取访问令牌
POST https://login.windows.net/common/oauth2/token
请求参数
这给了我一个accessToken和refreshToken。我可以使用此accessToken调用任何Power BI API。例如获取所有报告,克隆报告,创建数据集等。
现在我想将报告嵌入到我的网页中,并通过jquery使用此API
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并将Power BI图标显示为加载程序,然后引发此错误
{"message":"LoadReportFailed","detailedMessage":"Get report failed","errorCode":"403","level":6,"technicalDetails":{"requestId":"f62b4819-7cd0-1c6d-1af0-a89050881a8a"}}
我已经搜索了这个问题,人们说403是由于身份验证过程不正确而引起的。我在这里做什么错了?
答案 0 :(得分:1)
您似乎正在尝试嵌入指定错误令牌类型的报告。在您的代码令牌中,类型设置为Embed
:
tokenType: models.TokenType.Embed
尽管您从不提及生成了这样的内容(例如,使用GenerateTokenInGroup)。因此,您可能使用的是在初始身份验证期间获取的令牌。如果要使用它,则应将token type更改为Aad:
tokenType: models.TokenType.Aad
区别在于,Azure AD令牌可以访问用户的数据,报表,仪表板和图块,而嵌入式令牌则特定于嵌入式项目。此外,嵌入令牌的有效时间(〜5分钟)比AAD令牌(大约1小时)短。