0

I am trying to embed a Power Bi report in my application using a web browser. Everything works fine to connect to the workspace and get the token, but supplying the token to the web browser fails. I found a sample here Is it possible to embed power bi into desktop application? but it seems too old.

Here is my code:

Dim pbiClient = GetPowerBiClientAsApp()

Dim report = pbiClient.Reports.GetReportInGroupAsync(New Guid(wkspID), New Guid(ReportID))
report.Wait()
embedUrl = report.Result.EmbedUrl
Dim generateTokenRequestParameters = New Models.GenerateTokenRequest(accessLevel:="View")
Dim embedToken = pbiClient.Reports.GenerateTokenInGroupAsync(New Guid(wkspID), New Guid(ReportID), generateTokenRequestParameters)
embedToken.Wait()
tKn = embedToken.Result.Token

Dim parameters = New Object() {embedUrl, tKn, ReportID, "Report", 1, String.Empty}

AddHandler WebBrowser1.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted
WebBrowser1.Navigate(embedUrl)

and here is the code for WebBrowser1_DocumentCompleted event:

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs)
    Dim message = "{\""action\"":\""loadReport\"",\""accessToken\"":\""" & tKn & """\,""id\"":\""" & ReportID & """\,""\groupId\"":\""" & tenantID & """\,""\tokenType\"":""\models.TokenType.Embed\""}"
 WebBrowser1.Document.InvokeScript("postMessage", New Object() {message, "*"})
End Sub

Can you please help me?

preciousbetine
  • 2,959
  • 3
  • 13
  • 29

0 Answers0