यदि आप वही हासिल करना चाहते हैं, तो वहां वीडियो में रण ब्रुएर और एरिना हंटिस का प्रदर्शन क्या होता है!
आप इन कोड का उपयोग कर सकते हैं ...
प्रलेखन पढ़ने के बाद, मैं इस समाधान यह 5 दिन मुझे ले गया यह पता लगाने की के साथ आते हैं, वैसे भी मैं यहाँ पोस्ट कर रहा हूँ ताकि हर किसी को कोड के लिए आसान पहुँच हो सकता है।
** AppOwnData पावर द्वि एम्बेडेड रिपोर्ट **
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);
});
}
};
आपके रूटर 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 या जो भी आप
चाहते
<!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>
फ़ाइनल ly
स्थानीय होस्ट का आनंद लें: 4000/रिपोर्ट/अपने समूह आईडी यहाँ रखा/तुम यहाँ आईडी रिपोर्ट