Power BI API - 如何从 app.powerbi.com 获取报告? [英] Power BI API - How can I get reports from app.powerbi.com?

查看:42
本文介绍了Power BI API - 如何从 app.powerbi.com 获取报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用

如果您想使用 API 执行此操作,则需要 按组导出报告 REST API.要使用它,您需要获取一个访问令牌并将其添加到您的请求标头中.您可以通过调用一些AcuireToken 方法来自 ADAL.

您可以使用这样的代码(请注意示例中没有错误检查):

string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";//在 https://dev.powerbi.com/apps 获取string redirectUri = "https://login.live.com/oauth20_desktop.srf";string resourceUri = "https://analysis.windows.net/powerbi/api";string authorityUri = "https://login.windows.net/common/oauth2/authorize";AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache());//下午>安装包 Microsoft.IdentityModel.Clients.ActiveDirectoryvar authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));var accessToken = authenticationResult.AccessToken);string powerBIApiUrl = "https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportKey}/Export";//用实际值替换 groupId 和 reportKeyvar request = WebRequest.Create(powerBIApiUrl) as HttpWebRequest;request.KeepAlive = true;request.Method = "GET";request.ContentLength = 0;request.ContentType = "应用程序/json";request.Headers.Add("Authorization", $"Bearer {accessToken}");使用 (HttpWebResponse httpResponse = request.GetResponse() 作为 System.Net.HttpWebResponse){//读取httpResponse.GetResponseStream()获取.pbix文件}

I have some client that uses the Power BI App.
And with this API I want to get all the reports (.pbix) to my folder.

How can I get them?

解决方案

You can simply open the report in your browser and save it as .pbix file:

If you want to do this using an API, you will need Export Report In Group REST API. To use it, you need to acquire an access token and add it to your request header. You can acquire it by calling some of the AcuireToken methods from ADAL.

You can use code like this (please note there is no error checking in the example):

string clientId = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"; // Obtain at https://dev.powerbi.com/apps
string redirectUri = "https://login.live.com/oauth20_desktop.srf";
string resourceUri = "https://analysis.windows.net/powerbi/api";
string authorityUri = "https://login.windows.net/common/oauth2/authorize";

AuthenticationContext authContext = new AuthenticationContext(authorityUri, new TokenCache()); // PM> Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory

var authenticationResult = await authContext.AcquireTokenAsync(resourceUri, clientId, new Uri(redirectUri), new PlatformParameters(PromptBehavior.Auto));
var accessToken = authenticationResult.AccessToken);

string powerBIApiUrl = "https://api.powerbi.com/v1.0/myorg/groups/{groupId}/reports/{reportKey}/Export"; // Replace groupId and reportKey with actual values

var request = WebRequest.Create(powerBIApiUrl) as HttpWebRequest;
request.KeepAlive = true;
request.Method = "GET";
request.ContentLength = 0;
request.ContentType = "application/json";
request.Headers.Add("Authorization", $"Bearer {accessToken}");

using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
{
    //Read httpResponse.GetResponseStream() to get the .pbix file
}       

这篇关于Power BI API - 如何从 app.powerbi.com 获取报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆