Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
Hello,
This is the code that I have:
<?php
$clientId = 'xxx';
$clientSecret = 'xxx';
$tenantId = 'xxx';
$urlAccessToken = "https://login.windows.net/$tenantId/oauth2/token";
$resource = 'https://analysis.windows.net/powerbi/api';
$group = 'xxx';
$report ='xxx';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://login.microsoftonline.com/$tenantId/oauth2/token");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, array(
'resource' => $resource,
'client_id' => $clientId,
'client_secret' => $clientSecret,
'grant_type' => 'client_credentials'
));
$data = curl_exec($ch);
curl_close($ch);
$data_obj = json_decode($data);
$access_token = $data_obj->{"access_token"};
$headers = array(
"Content-Type: application/json",
"Authorization: Bearer $access_token"
);
$url = "https://api.powerbi.com/v1.0/myorg/groups/$group/reports/$report/GenerateToken";
#$url ="https://api.powerbi.com/v1.0/myorg/groups/$group/reports";
$post_params = array(
'accessLevel' => 'View'
);
$payload = json_encode($post_params);
$ch2 = curl_init( $url );
curl_setopt( $ch2, CURLINFO_HEADER_OUT, true);
curl_setopt( $ch2, CURLOPT_POSTFIELDS, $payload);
curl_setopt( $ch2, CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch2, CURLOPT_FAILONERROR, true);
$response = curl_exec( $ch2 );
if (curl_errno($ch2)) {
$error_msg = curl_error($ch2);
}
echo $response;
curl_close($ch2);
if (isset($error_msg)) {
echo $error_msg;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="/powerbi.js"></script>
</head>
<body>
<div id="reportContainer"></div>
</body>
<script>
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var embedConfiguration= {
type: 'report',
id: 'xxx', // the report ID
embedUrl: "<?php echo $url ?>",
accessToken: "<?php echo $access_token; ?>" ,
};
var $reportContainer = $('#reportContainer');
var report = powerbi.embed($reportContainer.get(0), embedConfiguration);
</script>
</html>
Thanks in advance!
Solved! Go to Solution.
Please make sure you are sending correct Token in the authorization header.
Also, make sure your user has all required permissions.
https://docs.microsoft.com/en-us/power-bi/developer/embedded/generate-embed-token
You can also refer to this blog for the same sample:
https://www.msbiblog.com/2018/01/12/power-bi-embedded-example-using-curl-and-php/
Please make sure you are sending correct Token in the authorization header.
Also, make sure your user has all required permissions.
https://docs.microsoft.com/en-us/power-bi/developer/embedded/generate-embed-token
You can also refer to this blog for the same sample:
https://www.msbiblog.com/2018/01/12/power-bi-embedded-example-using-curl-and-php/
User | Count |
---|---|
17 | |
11 | |
5 | |
4 | |
3 |