2017-08-28 44 views
1

は、私は私のProアカウントのすべてのクライアントIDとユーザ名・パスワードを交換しました。埋め込みパワーバイレポート

私はアプリ登録でネイティブアプリタイプを設定しました。私は埋め込みトークンを取得しようとしていた場合、次のエラーが来ている: enter image description here

を私は私のアプリに次の権限を与えている: enter image description here enter image description here

ここに私のコードです:

public async Task<ActionResult> EmbedReport() 
     { 

      // Create a user password credentials. 
      UserPasswordCredential UserCredentials = new UserPasswordCredential(Username, Password); 
      AuthenticationContext AuthContext = new AuthenticationContext(AuthorityUrl, false); 

      // Authenticate using created credentials 
      //AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, clientCred); 

      AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, ClientId, UserCredentials); 

      if (AuthResult == null) 
      { 
       return View(new EmbedConfig() 
       { 
        ErrorMessage = "Authentication Failed." 
       }); 
      } 

      var tokenCredentials = new TokenCredentials(AuthResult.AccessToken, "Bearer"); 

      // Create a Power BI Client object. It will be used to call Power BI APIs. 
      using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials)) 
      { 
       // Get a list of reports. 
       var reports = client.Reports.GetReports(); 

       // Get the first report in the group. 
       var report = reports.Value.FirstOrDefault(); 

       if (report == null) 
       { 
        return View(new EmbedConfig() 
        { 
         ErrorMessage = "Group has no reports." 
        }); 
       } 
       string accessLevel = "View"; 
       // Generate Embed Token. 
       var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel, report.DatasetId,false); 
       var tokenResponse = client.Reports.GenerateToken(report.Id, generateTokenRequestParameters); 


       if (tokenResponse == null) 
       { 
        return View(new EmbedConfig() 
        { 
         ErrorMessage = "Failed to generate embed token." 
        }); 
       } 

       // Generate Embed Configuration. 
       var embedConfig = new EmbedConfig() 
       { 
        EmbedToken = tokenResponse, 
        EmbedUrl = report.EmbedUrl, 
        Id = report.Id 
       }; 

       return View(embedConfig); 
      } 
     } 

答えて

1

私は「ログインしたユーザーとしてディレクトリにアクセスする」というアクセス許可を追加する必要があると思われます。
Power BIアカウントを持っていないユーザーのために、アプリケーション用のレポートとダッシュボードをどのように統合するかを説明します。

1 - まずアプリケーションをネイティブアプリとして登録しました。
2 - Azureのポータルでは、AzureのActive Directoryで、私は、アプリケーションの権限を付与します。 enter image description here

3 - 次に、このようなアプリケーションの権限を設定します。

enter image description here

enter image description here

私はあなたのように同じコードを使用しています。

希望します。

よろしくお願いいたします。

+0

他の誰かを明確にする...ポータルにログインし、アプリケーションからPower BIへの「偽装」したいユーザーとして「権限を許可する」。 GUIを介して公開されているAADアプリケーションを実際に持っていない場合は、これを行う必要があります(同意をより自然に確認できます) – Jmoney38

+0

このようなことは診断が難しいため、参考になるだけです。https:// github.com/Microsoft/PowerBI-Developer-Samples/issues/19 – Jmoney38

関連する問題