2017-11-09 11 views
10

क्या नोड जेएस में पावर बाय रेस्ट एपीआई का उपयोग करने का कोई तरीका है, मैंने वीडियो देखा, रान ब्रेउर और एरिना हंटिस यहां डेमो दिखा रहे थे, Setting up and Getting Started with Power BI Embedded मैं भी हासिल करना चाहता हूं लेकिन नोड जेएस का उपयोग करना चाहता हूं , हमारे विकास पर्यावरण में हम सी # का उपयोग नहीं करते हैं। मुझे नोड एसडीके मिला लेकिन यह कह रहा है कि हम अब नोड एसडीके का समर्थन नहीं करते हैं, Node SDKपावर द्वि आराम के साथ नोड जेएस ऐप एकीकरण एपी

क्या मुझे पावर बाय रेस्ट एपीआई का उपयोग करने के लिए नोड जेएस से सी # तक विकास संरचना को बदलना है !!

उत्तर

5

यदि आप वही हासिल करना चाहते हैं, तो वहां वीडियो में रण ब्रुएर और एरिना हंटिस का प्रदर्शन क्या होता है!

आप इन कोड का उपयोग कर सकते हैं ...

प्रलेखन पढ़ने के बाद, मैं इस समाधान यह 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/रिपोर्ट/अपने समूह आईडी यहाँ रखा/तुम यहाँ आईडी रिपोर्ट

-1

वे अब नोड एसडीके का समर्थन नहीं करते हैं, लेकिन क्या आपने इसे आजमाया है? यह अभी भी काम कर रहा है। आप कुछ प्रकार के एसडीके चाहते हैं - ऐसा लगता है कि not the easiest एपीआई के साथ काम करने के लिए है।

0

@ जो जॉय आपको क्या पता होना चाहिए।

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

यह लगभग प्राथमिकताओं इन कंपनी तय में परियोजना जो वे करते हैं।

वे इसके बारे में बहुत अच्छी प्रतिक्रिया दे सकते हैं। लेकिन जहां तक ​​चर्चा करने की कोई ऐसी योजना नहीं है। आप फीब 2017 से पहले एपीआई तक पहुंच सकते हैं।

यदि नया एपीआई आपको इसे अपने लिए आजमाने की ज़रूरत है। आप इसे लोक हो सकता है। हम कमांडिटी के रूप में योगदान देंगे।

2

मैं @Joyo वसीम कोड का उपयोग और सफलतापूर्वक एम्बेडेड रिपोर्ट डाल, तो मैं डैशबोर्ड एम्बेड करने के लिए प्रयास करें और यह काम करता है भी, मैंने यहां अपने कोड पोस्ट करने का फैसला किया है, इसलिए कोई भी जो डैशबोर्ड एम्बेड करने का प्रयास करता है, इन कोडों का उपयोग कर सकता है।

एंबेडेड डैशबोर्ड शक्ति का उपयोग द्वि रेस एपीआई

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 आदि

<!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>