Good day. I have a problem with displaying a PowerBi report in Xamarin.Forms app I'm making (newbie in PBI here). I only need to view report, I don't have to edit stuff. I got access token and after that I did a GET request and got embedded url from PowerBi which I used in WebView.Source to display on screen. And it loads to that report BUT it says I don't have permissions to view report which I should have (user I used for token is PBI PRO user). Text I get is "To view this report, ask the author for access". Here is token POST code
string url = "https://login.microsoftonline.com/<pbi_tenant_id>/oauth2/token";
IEnumerable<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("name", "testName"),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("scope", "openid"),
new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"),
new KeyValuePair<string, string>("client_id", "<client_id>"),
new KeyValuePair<string, string>("username", "<pro_user>"),
new KeyValuePair<string, string>("password", "<password>"),
new KeyValuePair<string, string>("client_secret", "<client_secret>")
};
HttpContent content = new FormUrlEncodedContent(parameters);
After all this I got my token, and I made GET request with that token to get embedded url
using (HttpResponseMessage response = await client.PostAsync(url, content))
{
if (response.IsSuccessStatusCode)
{
using (HttpContent contentOfReponse = response.Content)
{
try
{
string tokenResponseJSON = await contentOfReponse.ReadAsStringAsync(); //token in json format that I needed to convert to string in next line
var tokenRepsonse = JsonConvert.DeserializeObject<TokenInfoModel>(tokenResponseJSON);
string accessToken = tokenRepsonse.access_token; //my string token
try
{
string pbiUrl = "https://api.powerbi.com/v1.0/myorg/reports/<company_report_id>";
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken); //Authorization of request
var response2 = await client.GetStringAsync(pbiUrl);
var rese = JsonConvert.DeserializeObject<PBIRepost>(response2);
PbiEmbedUrl = rese.embedUrl + "&autoAuth=true" + "&isOwnedByMe=" + rese.isOwnedByMe + "apps/<app_id>";
RaisePropertyChanged(PbiEmbedUrl);
}
catch (Exception ex)
{
//await App.Current.MainPage.DisplayAlert();
}
}
catch (Exception)
{
//await App.Current.MainPage.DisplayAlert();
}
}
}
else
{
//await App.Current.MainPage.DisplayAlert();
}
}
All of this works, I got url and used it in WebView which opens to PBI website, but displays "To view this report, ask the author for access". Now something that may be really important, on my phone I am NOT a pro PBI user, but that should not be a problem because I used PBI PRO user for token. If that is a problem, how could I do it without being PRO user?
Embed url I got is: https://app.powerbi.com/reportEmbed?reportId=<report_id>&config=VST1BFLUItUFJeyJjbHVzdGVy5ldCIsImVtYmVkRmllZFRlbGVtZXWRpcmVjdC5hbmFseXNpcy53aW5kb3dzLm5ldCIsImVtYmVkRmVhdHVyZXMiOnsibRyeHVzdGVyVXJsIjoiaHR0cUVtYmVkIjp0cnVlfX0%3d" (not a real config string, not sure I can share real one, so I made it up for this question)
I did not mess with config in embedded url so that could also be the problem, but I don't know how could I edit config.