2017-07-27 59 views
0

我有一個獲取嵌入令牌的問題。我已經完成了這個鏈接(5 steps to push data into a dataset)中描述的全部5個步驟,並且一切都很完美:創建數據集,創建表格並填充數據,沒有任何問題。生成嵌入令牌創建問題

我有一個任務嵌入數據集(不報告)到網頁。 我發現這個頁面(Power BI Embeded Sample),它顯示了嵌入report/dataset/dashboard/tile的樣子。在這個頁面上有一個嵌入標記。 我GOOGLE了一下,發現這個頁面(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),但爲了我的目的我做了一些改變(因爲我需要數據集而不報告)。

我會很感激任何幫助。

回答

0

嘗試使用Power BI嵌入時遇到類似的錯誤。我建議使用像Fiddler這樣的工具來攔截應用程序和Power BI之間的通信,並找出實際返回的錯誤代碼。

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