2019 年如何在 Android 本机应用程序中添加 Power BI 报告

How to add Power BI reports in Android native app in 2019

我正在开发一个 Android 应用程序,我应该在其中显示 Power BI 报告和带有向下钻取的磁贴。

我用谷歌搜索,但仍然找不到合适的文档。

我知道有一个 Rest API,但是我找不到关于获取数据后究竟发生了什么的任何文档。 我看到其他 example/questions 他们在应用程序中嵌入了一个网络以显示仪表板,但我还没有看到完整的 example/video 工作。

请帮忙,提前致谢。

这里有一个 working example 给你。它展示了如何将 Power BI 元素嵌入到本机桌面应用程序中。对于 android,它基本上是相同的 - 它会在您的应用程序的网络浏览器中加载。

首先你要知道嵌入Power BI有两种模式——user owns dataapp owns data。对于第一种模式,在嵌入时,用户将使用自己的 Power BI Pro 帐户对自己进行身份验证,即您的每个用户都需要 Power BI Pro 许可证。对于后一种,您只需要一个 "master account",它将用于身份验证。实施中的差异并不大,因此我将描述 app owns data.

您需要执行以下操作:

  • 注册应用程序 - 转到 dev.powerbi.com/apps 并注册本机应用程序。 Select 授予它哪些权限(如果您不确定,对于您的第一次测试,只需授予它们所有权限)。复制 guid - 这是应用程序 ID,a.k.a。客户端 ID.

  • 下一步是从您的应用程序进行身份验证并获取访问令牌。为此使用 Azure Active Directory 身份验证库 (ADAL) - 调用 AuthenticationContext class 的一些 acquireToken 方法。这里有 the official examples for Android.

  • 使用此访问令牌调用 Power BI REST API 并获取要嵌入的元素的 embedUrl,例如report.

  • 使用Power BI JavaScript client to actually embed this element. You need to initialize one embed configuration class and pass information about element type (report, dashboard, tile), where to find it (embedUrl), authentication (access token), some other configuration options (show or hide filters pane, navigation, etc.), filters to be applied and so on. In case you will use the access token acquired above, set tokenType to be AAD. This token has many privileges, so for security reasons you may want to use Embed token instead. In this case use the access token to call the REST API again (e.g. Reports GenerateTokenInGroup).

  • 调用 JavaScript 客户端的 powerbi.embed 方法传递嵌入式配置以在您的应用程序中可视化此 Power BI 元素。