2017-07-27 18 views
0

埋め込みトークンを取得する際に問題があります。私はこのリンク(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)からこのコードを取りましたが、私は目的のためにいくつかの変更を行いました(データセットが必要で、報告しないため)。

私は何か助けていただきありがとうございます。

答えて

0

Power BIを使用して埋め込みしようとすると、同様のエラーが発生しました。 Fiddlerのようなツールを使用して、アプリケーションとPower BIの間の通信を傍受し、実際に返されるエラーコードを見つけることをお勧めします。

Telerikの次の記事は、Fiddlerを使用してトラフィックを傍受する方法を示しています。Capturing Traffic from .NET Services with Fiddler

関連する問題