2017-11-09 10 views
10

Czy istnieje sposób, w jaki korzystam z interfejsu API power bi odpoczynku w węźle js, obejrzałem wideo, Ran Breuer i Arina Hantsis pokazali tutaj demo, Setting up and Getting Started with Power BI Embedded Chcę osiągnąć to samo, ale używając węzła js , w naszym środowisku programistycznym nie używamy C#. Znalazłem pakiet SDK węzła, ale mówiąc, że już nie obsługujemy węzła SDK, Node SDKIntegracja aplikacji węzła js z mocą bi odpoczynku Api

Czy muszę zmienić strukturę programowania z Node js na C#, aby użyć power biasu Rest API !!

Odpowiedz

5

Jeśli chcesz osiągnąć to samo, to co pokazali Ran Breuer i Arina Hantsis w filmie!

można użyć tych kodów ...

po przeczytaniu dokumentacji, pochodzę z tego rozwiązania zajęło mi 5 dni, aby dowiedzieć się, w każdym razie jestem delegowania tutaj, więc każdy może mieć łatwy dostęp do kodów.

** AppOwnData zasilania bi wbudowane raporty **

Controller.js

const request = require('request'); 

const getAccessToken = function() { 

return new Promise(function (resolve, reject) { 

    const url = 'https://login.microsoftonline.com/common/oauth2/token'; 

    const username = ''; // Username of PowerBI "pro" account - stored in config 
    const password = ''; // Password of PowerBI "pro" account - stored in config 
    const clientId = ''; // Applicaton ID of app registered via Azure Active Directory - stored in config 

    const headers = { 
     'Content-Type': 'application/x-www-form-urlencoded' 
    }; 

    const formData = { 
     grant_type: 'password', 
     client_id: clientId, 
     resource: 'https://analysis.windows.net/powerbi/api', 
     scope: 'openid', 
     username: username, 
     password: password 
    }; 

    request.post({ 
     url: url, 
     form: formData, 
     headers: headers 
    }, function (err, result, body) { 
     if (err) return reject(err); 
     const bodyObj = JSON.parse(body); 
     resolve(bodyObj.access_token); 
    }); 
    }); 
    }; 

    const getReportEmbedToken = function (accessToken, groupId, reportId) { 

return new Promise(function (resolve, reject) { 

    const url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/reports/' + reportId + '/GenerateToken'; 

    const headers = { 
     'Content-Type': 'application/x-www-form-urlencoded', 
     'Authorization': 'Bearer ' + accessToken 
    }; 

    const formData = { 
     'accessLevel': 'view' 
    }; 

    request.post({ 
     url: url, 
     form: formData, 
     headers: headers 

    }, function (err, result, body) { 
     if (err) return reject(err); 
     const bodyObj = JSON.parse(body); 
     resolve(bodyObj.token); 
    }); 
}); 
}; 


    module.exports = { 
embedReport: function (req, res) { 
    getAccessToken().then(function (accessToken) { 
     getReportEmbedToken(accessToken, req.params.groupId, req.params.reportId).then(function (embedToken) { 
      res.render('index', { 
       reportId: req.params.dashboardId, 
       embedToken, 
       embedUrl: 'https://app.powerbi.com/reportEmbed?reportId=' + req.params.reportId + '&groupId=' + req.params.groupId 
      }); 
     }).catch(function (err) { 
      res.send(500, err); 
     }); 
    }).catch(function (err) { 
     res.send(500, err); 
    }); 
    } 
    }; 

Router index.js

const express = require('express'), 
    router = express.Router(), 
    mainCtrl = require('../controllers/MainController'); 
    router.get('/report/:groupId/:reportId', mainCtrl.embedReport); 
    module.exports = router; 

index.ejs czy co tam chcesz

<!DOCTYPE html> 
    <html> 

    <head> 
    <title>Node.js PowerBI Embed</title> 
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css" /> 
    <style> 
    html, 
    body { 
    height: 100%; 
    } 

.fill { 
    min-height: 100%; 
    height: 100%; 
    box-sizing: border-box; 
} 

#reportContainer { 
    height: 100%; 
    min-height: 100%; 
    display: block; 
} 
</style> 
</head> 
<body> 
<div class="container-fluid fill"> 
<div id="reportContainer"></div> 
</div> 
<script src="/jquery/dist/jquery.min.js"></script> 
<script src="/bootstrap/dist/js/bootstrap.min.js"></script> 
<script src="/powerbi-client/dist/powerbi.js"></script> 
<script> 
const models = window['powerbi-client'].models; 
const config = { 
    type: 'report', 
    tokenType: models.TokenType.Embed, 
    accessToken: '<%- embedToken %>', 
    embedUrl: '<%- embedUrl %>', 
    id: '<%- reportId %>' 
    }; 
    // Get a reference to the embedded dashboard HTML element 
    const reportContainer = $('#reportContainer')[0]; 
    // Embed the dashboard and display it within the div container. 
    powerbi.embed(reportContainer, config); 
</script> 
</body> 

</html> 

Finał ly Ciesz

localhost: 4000/raport/umieścić swój identyfikator grupy tutaj/postawić zgłosić id tutaj

-1

Nie obsługują już zestawu SDK węzła, ale czy próbowałeś go? Nadal może działać. Będziesz potrzebował jakiegoś SDK - wydaje się, że to jest not the easiest API do pracy.

0

@Jo Joy, co widziałem, powinieneś wiedzieć.

https://github.com/Microsoft/PowerBI-Node/issues/40

to około Priorytety te przedsiębiorstwa zdecydować, w którym projekt robią.

Mogą bardzo dobrze o tym reagować. Ale jeśli chodzi o dyskusję, nie ma takiego planu. Możesz uzyskać dostęp do API przed lutym 2017.

Jeśli nowszy api musisz spróbować go dla swojego. Możesz być tym ludem. My jako wspólnota wniesiemy swój wkład.

2

użyłem kodów @Joyo waseem i skutecznie osadzone raport, a potem dać szansę, aby umieścić panel i działa też, postanowiłem opublikować tutaj moje kody, aby każdy, kto próbuje osadzić Dashboard, może korzystać z tych kodów.

Wbudowany Kokpit stosując moc bi Res API

Controler.js

const request = require('request'); 

    const getAccessToken = function() { 

    return new Promise(function (resolve, reject) { 

    const url = 'https://login.microsoftonline.com/common/oauth2/token'; 

    const username = ''; // Username of PowerBI "pro" account - stored in config 
    const password = ''; // Password of PowerBI "pro" account - stored in config 
    const clientId = ''; // Applicaton ID of app registered via Azure Active Directory - stored in config 

    const headers = { 
     'Content-Type': 'application/x-www-form-urlencoded' 
    }; 

    const formData = { 
     grant_type: 'password', 
     client_id: clientId, 
     resource: 'https://analysis.windows.net/powerbi/api', 
     scope: 'openid', 
     username: username, 
     password: password 
    }; 

    request.post({ 
     url: url, 
     form: formData, 
     headers: headers 
    }, function (err, result, body) { 
     if (err) return reject(err); 
     const bodyObj = JSON.parse(body); 
     resolve(bodyObj.access_token); 
    }); 
    }); 
    }; 

const getEmbedToken = function (accessToken, groupId, dashboardId) { 

return new Promise(function (resolve, reject) { 

    const url = 'https://api.powerbi.com/v1.0/myorg/groups/' + groupId + '/dashboards/' + dashboardId + '/GenerateToken'; 

    const headers = { 
     'Content-Type': 'application/x-www-form-urlencoded', 
     'Authorization': 'Bearer ' + accessToken 
    }; 

    const formData = { 
     'accessLevel': 'View' 
    }; 

    request.post({ 
     url: url, 
     form: formData, 
     headers: headers 

    }, function (err, result, body) { 
     if (err) return reject(err); 
     const bodyObj = JSON.parse(body); 
     resolve(bodyObj.token); 
    }); 
    }); 
    }; 


    module.exports = { 
prepareView: function(req, res) { 
    getAccessToken().then(function(accessToken) { 
     console.log(req.params.groupId); 
     getEmbedToken(accessToken, req.params.groupId, req.params.dashboardId).then(function(embedToken) { 
      res.render('index', { 
       dashboardId: req.params.dashboardId, 
       embedToken, 
       embedUrl: 'https://app.powerbi.com/dashboardEmbed?dashboardId=' + req.params.dashboardId + '&groupId=' + req.params.groupId 
      }); 
     }); 
    }); 
} 
}; 

index.js

const express = require('express'), 
    router = express.Router(), 
    mainCtrl = require('../controllers/MainController'); 
    router.get('/dashboard/:groupId/:dashboardId', mainCtrl.prepareView); 
    module.exports = router; 

index.ejs etc.

<!DOCTYPE html> 
    <html> 
     <head> 
    <title>Node.js PowerBI Embed</title> 
    <link rel="stylesheet" href="/bootstrap/dist/css/bootstrap.min.css" /> 
    <style> 
    html, 
    body { 
    height: 100%; 
    } 

.fill { 
    min-height: 100%; 
    height: 100%; 
    box-sizing: border-box; 
} 

    #dashboardContainer { 
    height: 100%; 
    min-height: 100%; 
    display: block; 
    } 
</style> 
</head> 
<body> 
    <div class="container-fluid fill"> 
<div id="dashboardContainer"></div> 
</div> 
<script src="/jquery/dist/jquery.min.js"></script> 
<script src="/bootstrap/dist/js/bootstrap.min.js"></script> 
<script src="/powerbi-client/dist/powerbi.js"></script> 
<script> 
const models = window['powerbi-client'].models; 
const config = { 
    type: 'dashboard', 
    tokenType: models.TokenType.Embed, 
    accessToken: '<%- embedToken %>', 
    embedUrl: '<%- embedUrl %>', 
    id: '<%- dashboardId %>' 
    }; 
// Get a reference to the embedded dashboard HTML element 
    const dashboardContainer = $('#dashboardContainer')[0]; 
// Embed the dashboard and display it within the div container. 
    powerbi.embed(dashboardContainer, config); 
    </script> 
    </body> 
    </html> 
Powiązane problemy