我使用ADAL.js和PowerBI.js通过“用户拥有数据”方法嵌入Power BI报表。为此,我已经在Azure中注册了“ Web应用程序/ API”应用程序。这是我正在使用的代码:
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.7.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/jquery-ui.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.3/es6-shim.js"></script>
<script src="powerbi.min.js"></script>
<script src="adal.min.js"></script>
<script type="text/javascript">
(function() {
"use strict";
var config = {
instance: 'https://login.microsoftonline.com/',
tenant: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // I put my Directory ID here
clientId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // I put Application ID of my Azure Registered App here
postLogoutRedirectUri: window.location.origin,
redirectUri: 'https://login.microsoftonline.com/common/oauth2/authorize',
resource: 'https://analysis.windows.net/powerbi/api',
prompt: 'none',
cacheLocation: 'localStorage',
embedUrlBase: 'https://app.powerbi.com/reportEmbed',
groupId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // My Power BI group
reportId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', // My Power BI report
response_type:'id_token'
};
var authContext = new AuthenticationContext(config);
var isCallback = authContext.isCallback(window.location.hash);
authContext.handleWindowCallback();
if (isCallback && !authContext.getLoginError()) {
window.location = authContext._getItem(authContext.CONSTANTS.STORAGE.LOGIN_REQUEST);
}
var user = authContext.getCachedUser();
if (!user) {
authContext.login();
}
authContext.acquireToken(config.resource, function(error, token) {
if (error || !token) {
alert('ADAL error occurred: ' + error);
console.log('ADAL error occurred: ' + error);
return;
}
config.authToken = token;
$(document).ready(function() {
var models = window['powerbi-client'].models;
var embedUrl = "https://app.powerbi.com/reportEmbed?reportId="+ config.reportId +"&groupId="+ config.groupId;
var pbiconfig = {
type: 'report',
tokenType: models.TokenType.Aad,
accessToken: config.authToken,
embedUrl: embedUrl,
id: config.reportId,
pageView: 'fitToWidth'
};
var pbiconfigmessage = JSON.stringify(pbiconfig);
var reportContainer = $('#reportContainer')[0];
var report = powerbi.embed(reportContainer, pbiconfig);
var report1 = powerbi.get(reportContainer);
report1.fullscreen();
});
});
})();
</script>
当我尝试运行此代码时,出现此错误:
AADSTS90014:请求正文必须包含以下参数: 'client_id'
可能是什么问题?如您所见,我在配置中提供了正确的clientId。
谢谢大家。
答案 0 :(得分:0)
您已经编写了clientId。从错误消息来看,该字段似乎需要写为client_id。