最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - steps to integrate PowerBI report on Java application - Stack Overflow

programmeradmin1浏览0评论

JavaScripts Required jquery.js powerbi.js

  1. Generate AAD token

I assume that you have Native application built already and all required Power BI Access has been given.If not then refer steps A to C below.

I used the steps mentioned on this link.I modified it a bit to reuse token till it get expired.Only after expiration,we will generate new token This application will give AAD token for REST call received

  1. Create DIV for Report On JSP page of application that need Report to be embeded

    div id="reportContainer" class="reportContainer"

  2. Get AAD token

Make REST call to application developed at Step 1 get AAD token

my aadToken object has 2 parameters accessToken and expiresAtStr

var aadToken={accessToken:' ',expiresAtStr: ''};

function getAadAccessToken() {
    var deferred = $q.defer();
    $http.get('/MyPowerBIApp/REST/getAadToken/')
        .then(
        function (response) {
            deferred.resolve(response.data);
        },
        function(errResponse){
            console.error('Error while getting Aad Access Token');
            deferred.reject(errResponse);
        }
    );
    return deferred.promise;
}   

After receiving aadToken from REST call, create Embed Configuration

txtAccessToken is aad token from above.(aadToken.accessToken) txtEmbedUrl is the report that needs to be embedded. It will be like .......

 var config= {
                     type: 'report',
                     tokenType: 0,//1:Embed,0:Aad
                     accessToken: txtAccessToken,
                     embedUrl: txtEmbedUrl,
                     permissions: 7,
                     viewMode: 0,
                     settings: {
                         filterPaneEnabled: false,
                         navContentPaneEnabled: false,
                         useCustomSaveAsDialog: false
                     }
                 };
var $reportContainer = $('#reportContainer'); 
var report = powerbi.embed($reportContainer.get(0), config); 

This will embed report on to the DIV


Major mistakes occurred while trying to embed was on generating AAD Token. Make sure you have created Azure application and has given all required permissions to use Power BI APIs

A. Create Native App as mentioned here:

B. Go to Azure Active Directory-> App registrations Click on Your Application : Application ID value that you see here is the clientId value that you will use for AAD Token generation mentioned on step 1

Please refer below code:

AuthenticationResult authResult = authenticationContext.acquireToken(
            resourceId,
            clientId,
            username,
            password,
            null
    ).get();

C. Go To Azure Active Directory-> App registrations ->Settings ->Required permissions

Make sure that Power BI Service (Power BI) is under the API and all required permissions are given.Below are few of the permissions View users Groups View All Reports View All Dashboards(Preview)

If all these steps are done,you should be able to embed the report with the token received. Please check and let me know if I had missed any steps or there will be any issues on this approach.

Also Make sure that the username that will be used to generate AAD Token is having access(MemberOf) PowerBI workspace where the Report resides

发布评论

评论列表(0)

  1. 暂无评论