大家好。我可能没有完全理解如何在我的 Xamarin 应用程序中嵌入 PBI 报告。我得到了我的访问令牌并为此使用了主用户,但是在我 GET EmbedUrl 并将其放入 WebView 的 Source 属性之后,我收到一条消息:“请唱歌以查看此报告”。这是一个问题,因为我的客户没有 PowerBi 帐户,我希望他们能够看到此报告。问题可能出在我用来获取访问令牌的标题中,所以下面是我使用的代码
string url = "https://login.microsoftonline.com/" + tennant_id + "/oauth2/token"; //url to which I POST to
IEnumerable<KeyValuePair<string, string>> parameters = new List<KeyValuePair<string, string>>()
{
new KeyValuePair<string, string>("authenticationType", "MasterUser"),
new KeyValuePair<string, string>("name", "<name>"),
new KeyValuePair<string, string>("workspaceId", "<workspaceId>"),
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("scope", "https://analysis.windows.net/powerbi/api/.default"),
new KeyValuePair<string, string>("resource", "https://analysis.windows.net/powerbi/api"),
new KeyValuePair<string, string>("authorityUrl", "https://login.microsoftonline.com/organizations/"),
new KeyValuePair<string, string>("urlPowerBiServiceApiRoot", "https://api.powerbi.com/"),
new KeyValuePair<string, string>("client_id", "<clientID>"),
new KeyValuePair<string, string>("username", "<username>"),
new KeyValuePair<string, string>("password", "<password>"),
new KeyValuePair<string, string>("client_secret", "<clientSecret>")
};
获得访问令牌后,我在 GET 请求中使用它来
https://api.powerbi.com/v1.0/myorg/reports/<report_it>
我通过 AuthenticationHeader 作为
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", accessToken);
然后我得到了我在 WebView Source 属性中使用的嵌入 URL,但我没有登录。当我登录时,我看到了这个报告,否则我不能。我在哪里犯了错误/错误?我是 PowerBi 嵌入的新手,所以请像对孩子一样解释它。
