【问题标题】:Generate Embed Token For Create Issue为创建问题生成嵌入令牌
【发布时间】:2017-07-27 06:39:21
【问题描述】:

我在获取嵌入令牌时遇到问题。我已完成此链接 (5 steps to push data into a dataset) 中描述的所有 5 个步骤,并且一切正常:创建数据集、创建表并用数据填充数据,没有任何问题。

我的任务是将数据集(不是报告)嵌入到网页中。 我找到了这个页面 (Power BI Embeded Sample),它显示了嵌入报告/数据集/仪表板/磁贴的外观。在这个页面上有一个嵌入令牌。 我用谷歌搜索了一下,发现这个页面(Generate Embed Token Example)描述了 HTTP POST 请求的外观。我为数据集做了部分。这是我的代码示例:

private static void generateEmbedToken()
    {
        // TokenCredentials Initializes a new instance of the
        // Microsoft.Rest.TokenCredentials class with
        // the given 'Bearer' token.
        var credentials = new TokenCredentials(token);
        // Initialize PowerBIClient with credentials
        var powerBIclient = new Microsoft.PowerBI.Api.V2.PowerBIClient(credentials)
        {
            // BaseUri is the api endpoint, default is https://api.powerbi.com
            BaseUri = new Uri("https://api.powerbi.com")
        };
        try
        {
            // Create body where accessLevel = View, datasetId = "" by default
            var requestParameters = new GenerateTokenRequest(TokenAccessLevel.Create, datasetId, true);
            // Generate EmbedToken This function sends the POST message
            //with all parameters and returns the token
            EmbedToken token = powerBIclient.Reports.GenerateTokenForCreate(requestParameters);
            embedToken = token.Token;
        }
        catch (Exception exc)
        {
            Console.WriteLine(exc.ToString());
        }
    }

我得到了下一个错误:

Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'NotFound'
   at Microsoft.PowerBI.Api.V2.Reports.<GenerateTokenForCreateWithHttpMessagesAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerBI.Api.V2.ReportsExtensions.<GenerateTokenForCreateAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.PowerBI.Api.V2.ReportsExtensions.GenerateTokenForCreate(IReports operations, GenerateTokenRequest requestParameters)
   at PushDataApp.Program.generateEmbedToken() in C:\Users\PC\Documents\Visual Studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 388

这是第 388 行:

EmbedToken token = powerBIclient.Reports.GenerateTokenForCreate(requestParameters);

我不知道为什么会这样。 我从这里 (Generate Embed Token Example) 获取了这段代码,但出于我的目的我做了一些更改(因为我需要数据集而不是报告)。

我将不胜感激。

【问题讨论】:

    标签: c# powerbi powerbi-embedded


    【解决方案1】:

    我在尝试使用 Power BI 进行嵌入时遇到了类似的错误。我建议使用 Fiddler 之类的工具来拦截应用程序和 Power BI 之间的通信,并找出实际返回的错误代码。

    Telerik 的以下文章展示了如何使用 Fiddler 拦截流量:Capturing Traffic from .NET Services with Fiddler

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-13
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-30
      相关资源
      最近更新 更多