We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Hi everyone,
How to fix https://api.powerbi.com/powerbi/globalservice/v201606/clusterdetails (401).
I am embedded in my .net framework (webforms) application, a paginated report from power bi service, when I press a button I need the report to appear.
When I click the button, the report should open in a container, but I get the error I mentioned above. The strange thing is that the report can be seen using the Microsoft application 'Power BI Embedded Sample', but it is not shown in my application.
In the Microsoft application, however, it can be seen embedded
ASPX File:
(javascript)
<script type="text/javascript">
function embedReport() {
var models = window['powerbi-client'].models;;
let embedConfiguration = {
accessToken: '<%= LiteralAccessToken.Text %>',
embedUrl: '<%= LiteralEmbedUrl.Text %>',
id: '<%= LiteralReportId.Text %>',
tokenType: models.TokenType.Aad,
type: 'report'
};
let dashboardContainer = $('#reportContainer')[0];
let dashboard = powerbi.embed(dashboardContainer, embedConfiguration);
}
document.addEventListener('DOMContentLoaded', function () {
embedReport();
});
</script>
(body)
...........................
<asp:Literal ID="LiteralReportId" runat="server" Visible="false"></asp:Literal>
<asp:Literal ID="LiteralEmbedUrl" runat="server" Visible="false"></asp:Literal>
<asp:Literal ID="LiteralTokenType" runat="server" Visible="false"></asp:Literal>
<asp:Literal ID="LiteralAccessToken" runat="server" Visible="false"></asp:Literal>
<asp:Button ID="btnLoadReport" runat="server" OnClick="btnLoadReport_Click" Text="Cargar Reporte" />
<div id="reportContainer" style="height: 600px; width: 100%;"></div>
.............................
CS File:
.............................................................................
protected void btnLoadReport_Click(object sender, EventArgs e)
{
EmbedPowerBIReport().Wait();
}
private async Task EmbedPowerBIReport()
{
Guid groupId = new Guid("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Guid reportId = new Guid("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy");
using (HttpClient httpClient = new HttpClient())
{
// Obtén el token de acceso
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("client_id", clientId),
new KeyValuePair<string, string>("client_secret", clientSecret),
new KeyValuePair<string, string>("scope", "https://analysis.windows.net/powerbi/api/.default")
});
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
var tokenResponse = await httpClient.PostAsync("https://login.microsoftonline.com/zzzzzzzzzzzzzzzzzzzzzzzzzzzzz/oauth2/v2.0/token", content);
var tokenContent = await tokenResponse.Content.ReadAsStringAsync();
var token = Newtonsoft.Json.JsonConvert.DeserializeObject<TokenResponse>(tokenContent);
TokenCredentials tokenCredentials = new TokenCredentials(token.access_token, "Bearer");
using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
{
var report = await client.Reports.GetReportInGroupAsync(groupId, reportId);
LiteralReportId.Text = reportId.ToString();
LiteralEmbedUrl.Text = report.EmbedUrl;
LiteralTokenType.Text = token.token_type;
LiteralAccessToken.Text = token.access_token;
}
}
ScriptManager.RegisterStartupScript(this, GetType(), "embedReport", "embedReport();", true);
}
...............................................................................
Help me please!
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.