【问题标题】:Linking Power BI with Python to download Reports and send it to a whatsApp contact将 Power BI 与 Python 链接以下载报告并将其发送给 WhatsApp 联系人
【发布时间】:2021-07-26 16:29:39
【问题描述】:

我手头的问题是,我正在尝试自动化从 Power BI 下载报告的过程,并在 Python 的帮助下将其发送给各种 WhatsApp 联系人。

这可能吗?

我找到了可用于下载报告的 Microsoft REST API,但我在尝试配置我的凭据和其他内容时迷失了方向。

【问题讨论】:

  • 是否要获取 Azure DevOps 报告?

标签: python powerbi whatsapp powerbi-rest-api


【解决方案1】:

查看以下情况下的回复Power BI API - How can I get reports from app.powerbi.com?

如果您想使用 API 执行此操作,则需要 Export Report In Group REST API。要使用它,您需要获取访问令牌并将其添加到您的请求标头中。您可以通过调用ADAL 中的一些AcuireToken 方法来获取它。

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

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
}   

此外,还有其他有用的链接:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-28
    • 1970-01-01
    • 2020-07-18
    • 1970-01-01
    • 1970-01-01
    • 2020-03-14
    相关资源
    最近更新 更多