首页 > 解决方案 > 将 PowerBI 仪表板/报表嵌入 Web 应用程序

问题描述

我正在尝试将 Power BI Dash Board 报告嵌入到 Web 应用程序中。

1) 我已经使用此 Microsoft 链接及其来自 github https://docs.microsoft.com/en-us/power-bi/developer/embed-sample-for-your-organization的示例应用程序配置了应用程序。

2)我也尝试使用此文档进行配置https://bitbucket.org/omnistream/powerbi-api-example \

我正在使用我的公司电子邮件 ID /password 访问端点。以下是详细信息。我拥有仪表板报告的管理员权限,并且拥有 Power BI pro 用户帐户。

发布端点:https ://login.microsoftonline.com/common/oauth2/token

请求标头:用户代理:提琴手主机:login.windows.net 内容类型:application/x-www-form-urlencoded 内容长度:xxx

请求正文:grant_type=password&scope=openid&username=myUserName@mycompany.com&password=MyPassword&client_id=XXXXX&resource= https://analysis.windows.net/powerbi/api&client_secret=XXXXX

它抛出以下错误:error_description=AADSTS70002:验证凭据时出错。AADSTS50126:用户名或密码无效 跟踪 ID:c13c59dc-79e2-4169-bae2-06c402310100 相关 ID:a747a226-362a-45aa-956a-122629fa9863 时间戳:2018-08-06 21:27:59Z

我需要单独配置或创建 Master Power BI 帐户吗?

或者如果我的公司网络干扰 Post 请求以屏蔽用户 ID/密码,是否有任何工具可以帮助我跟踪此网络问题?

标签: c#powerbi

解决方案


即使绕过公司代理以获取凭据,它也无法正常工作。最后,我向 Microsoft 记录了票证,并且能够使其仅适用于其中一个选项,即本机应用程序。下面是步骤

1) 从这里下载“App 拥有数据”应用程序。并在 Azure 门户中将您的 power Bi 应用程序注册为应用程序类型的“本机应用程序”。有关配置 PowerBI 应用程序网页嵌入的详细信息,请访问相关链接 #1。

2) 打开项目并使用 NUget 包管理器导入所有需要的 Dll。

3) 在项目中使用这些值配置 cloud.config。

  <appSettings>
  <add key="authorityUrl" value="https://login.microsoftonline.com/common/oauth2/authorize/" />
  <add key="resourceUrl" value="https://analysis.windows.net/powerbi/api" />   
  <add key="apiUrl" value="https://api.powerbi.com/" />
  <add key="embedUrlBase" value="https://app.powerbi.com/v1.0/myorg/" /> 
</appSettings>

4) 在项目中使用这些值配置您的 web.config 文件。

    <appSettings file="Cloud.config">
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />    
    <add key="applicationId" value="xxxxxxx-xxxx-xxxx-xxxx-xxxxxx" /> <!--For PowerBI Native application ID-->    
    <add key="workspaceId" value="xxxxxxx-xxxx-xxxx-xxxx-xxxxxx" />
    <!-- The id of the report to embed. If empty, will use the first report in group -->     
    <add key="reportId" value="xxxxxxx-xxxx-xxxx-xxxx-xxxxxx" />
    <!-- Note: Do NOT leave your credentials on code. Save them in secure place. -->
    <add key="pbiUsername" value="XXXXXXXXX@yourcompany.com" />
    <add key="pbiPassword" value="xxxxxxxx" />    
  </appSettings>

5) 在 Power BI 网站上发布您的报告,创建仪表板,在上面的 web.config 设置中填写报告 ID 和工作空间 ID。

6) 执行应用程序。它应该适用于嵌入报告、仪表板和磁贴类型。


推荐阅读