简体   繁体   English

Power BI REST API Power Query/Power BI 中的使用数据

[英]Power BI REST API Usage data in Power Query/Power BI

I am trying to get usage data from Power BI into Power BI desktop in order to create an admin report.我正在尝试将使用数据从 Power BI 获取到 Power BI 桌面,以创建管理报告。 The report will show the usage of the different reports in Power BI.该报告将显示 Power BI 中不同报告的使用情况。

In order to get this data I am using the Power BI REST APIs.为了获取这些数据,我使用了 Power BI REST API。 Specifically calls such as:具体调用如:

GET https://api.powerbi.com/v1.0/myorg/admin/datasets -- To get datasets
GET https://api.powerbi.com/v1.0/myorg/admin/apps?$top={$top} -- To get apps

To get datasets in Power Query I can then write:要在 Power Query 中获取数据集,我可以编写:

let
Source = Json.Document(
Web.Contents(
"https://api.powerbi.com/v1.0/myorg/admin/datasets", [Headers=[Authorization="Bearer MYKEY"]]))
in Source

This does retrieve the datasets.这确实检索数据集。 However the key used is taken from https://docs.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-apps-as-admin#code-try-0但是使用的密钥取自https://docs.microsoft.com/en-us/rest/api/power-bi/admin/apps-get-apps-as-admin#code-try-0

This link allows a user to try the API, which gives you a temporary key.此链接允许用户试用 API,它会为您提供临时密钥。 In order to get a refreshable token/key, another call must be made to the API.为了获得可刷新的令牌/密钥,必须再次调用 API。 In order to make this call I have created an application in Azure which has been granted rights by our admin.为了进行此调用,我在 Azure 中创建了一个应用程序,该应用程序已由我们的管理员授予权限。 In order to retrieve the refreshable token, I have written this in Power Query (by using Azure HTTP POST requests for an access token from Power BI ):为了检索可刷新的令牌,我在 Power Query 中编写了这个(通过使用Azure HTTP POST 请求来自 Power BI 的访问令牌):

  () =>
let
  apiUrl = "https://login.windows.net/MY TENANT ID/oauth2/token",
    body = [
          client_id="My Client ID",
          grant_type="client_credentials",
          client_secret="My Client Secret",
          resource="https://analysis.windows.net/powerbi/api"
],

  Source = Json.Document(Web.Contents(apiUrl, [Headers = [Accept = "application/json"],
 Content = Text.ToBinary(Uri.BuildQueryString(body))]))
in
Source

This call is successful and returns me the following (Photo):此调用成功并返回以下内容(照片): 可刷新令牌

The natural progression would then be to paste the generated access token into my first query, but this gives me an access error.然后自然的进展是将生成的访问令牌粘贴到我的第一个查询中,但这会给我一个访问错误。 "Expression.Error: Access to the resource is forbidden." “Expression.Error:禁止访问资源。” When changing the data sources settings from anonymous to Windows I get another error message: "Expression.Error" The 'Authorization' header is only supported when connecting anonymously..."将数据源设置从匿名更改为 Windows 时,我收到另一条错误消息: “Expression.Error”“授权”header 仅在匿名连接时受支持...”

Any ideas on what to do in order to get the data into Power BI would be greatly appreciated.任何关于如何将数据导入 Power BI 的想法将不胜感激。 Thanks.谢谢。

It is probably not the answer you are looking for but my team was attempting to do the very same thing and found the only way to get this to work was to add some form of data store between PBI admin logs and the PBI dataset.这可能不是您正在寻找的答案,但我的团队正在尝试做同样的事情,并发现让它工作的唯一方法是在 PBI 管理日志和 PBI 数据集之间添加某种形式的数据存储。 We use CSV's and a sql database but an Azure Job runs on a schedule and collects the data and stores it locally, then PBI reads that stored data.我们使用 CSV 和 sql 数据库,但 Azure 作业按计划运行并收集数据并将其存储在本地,然后 PBI 读取存储的数据。

This is not a direct answer to your question, but you can build admin reports from the Power BI Service data using the Power BI REST API Connector from Github ( link ).这不是您问题的直接答案,但您可以使用来自 Github 的 Power BI REST API连接器从 Power BI 服务数据构建管理报告。 Then you can connect to the service directly from PBI Desktop, without dealing yourself with OAuth and/or AAD authentication.然后,您可以直接从 PBI Desktop 连接到服务,而无需自己处理 OAuth 和/或 AAD 身份验证。 The connector has some limitations, but it was very useful for our reporting.连接器有一些限制,但它对我们的报告非常有用。

I don't know if you can install this custom connector in the Power BI Service, but it works perfectly in Power BI Desktop.我不知道您是否可以在 Power BI 服务中安装此自定义连接器,但它在 Power BI Desktop 中可以完美运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM