<legend id='Vh4iG'><style id='Vh4iG'><dir id='Vh4iG'><q id='Vh4iG'></q></dir></style></legend>
      <i id='Vh4iG'><tr id='Vh4iG'><dt id='Vh4iG'><q id='Vh4iG'><span id='Vh4iG'><b id='Vh4iG'><form id='Vh4iG'><ins id='Vh4iG'></ins><ul id='Vh4iG'></ul><sub id='Vh4iG'></sub></form><legend id='Vh4iG'></legend><bdo id='Vh4iG'><pre id='Vh4iG'><center id='Vh4iG'></center></pre></bdo></b><th id='Vh4iG'></th></span></q></dt></tr></i><div id='Vh4iG'><tfoot id='Vh4iG'></tfoot><dl id='Vh4iG'><fieldset id='Vh4iG'></fieldset></dl></div>

      <tfoot id='Vh4iG'></tfoot>

      <small id='Vh4iG'></small><noframes id='Vh4iG'>

      • <bdo id='Vh4iG'></bdo><ul id='Vh4iG'></ul>

      1. 如何使用非交互式身份验证连接到 Power BI API?

        时间:2023-08-28

              <tbody id='5O4Ou'></tbody>

              <small id='5O4Ou'></small><noframes id='5O4Ou'>

              <i id='5O4Ou'><tr id='5O4Ou'><dt id='5O4Ou'><q id='5O4Ou'><span id='5O4Ou'><b id='5O4Ou'><form id='5O4Ou'><ins id='5O4Ou'></ins><ul id='5O4Ou'></ul><sub id='5O4Ou'></sub></form><legend id='5O4Ou'></legend><bdo id='5O4Ou'><pre id='5O4Ou'><center id='5O4Ou'></center></pre></bdo></b><th id='5O4Ou'></th></span></q></dt></tr></i><div id='5O4Ou'><tfoot id='5O4Ou'></tfoot><dl id='5O4Ou'><fieldset id='5O4Ou'></fieldset></dl></div>
            • <legend id='5O4Ou'><style id='5O4Ou'><dir id='5O4Ou'><q id='5O4Ou'></q></dir></style></legend>
                <bdo id='5O4Ou'></bdo><ul id='5O4Ou'></ul>

                  <tfoot id='5O4Ou'></tfoot>

                1. 本文介绍了如何使用非交互式身份验证连接到 Power BI API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  用 C# 编码.我正在关注本指南:

                  Coding in C#. I'm following this guide:

                  https://azure.microsoft.com/en-us/documentation/articles/resource-group-authenticate-service-principal/#authenticate-service-principal-with-password---powershell%E2%80%8C%E2%80%8B

                  但它不起作用,而且它不是 Power BI 特定的,所以我不确定如何将它应用到 Power BI API.

                  But it is not working and it is not Power BI specific so I'm not sure exactly how to apply it to the Power BI API.

                  在尝试连接到 Power BI 时,我收到了 403 Forbidden 响应.

                  In my attempt to connect to Power BI I am getting a 403 Forbidden response.

                          var authenticationContext = new AuthenticationContext("https://login.windows.net/" + Properties.Settings.Default.TenantID);
                          var credential = new ClientCredential(clientId: Properties.Settings.Default.ClientID, clientSecret: Properties.Settings.Default.ClientSecretKey);
                          var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential);
                  
                          if (result == null)
                          {
                              throw new InvalidOperationException("Failed to obtain the JWT token");
                          }
                  
                          string accessToken = result.AccessToken;
                  
                  
                          string responseContent = string.Empty;
                  
                          //The resource Uri to the Power BI REST API resource
                          string datasetsUri = "https://api.powerbi.com/v1.0/myorg/datasets";
                  
                          //Configure datasets request
                          System.Net.WebRequest request = System.Net.WebRequest.Create(datasetsUri) as System.Net.HttpWebRequest;
                          request.Timeout = 20000;
                          request.Method = "GET";
                          request.ContentLength = 0;
                          request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken));
                  
                          try
                          {
                  
                              //Get datasets response from request.GetResponse()
                              using (var response = request.GetResponse() as System.Net.HttpWebResponse)
                              {
                                  //Get reader from response stream
                                  using (var reader = new System.IO.StreamReader(response.GetResponseStream()))
                                  {
                                      responseContent = reader.ReadToEnd();
                  
                                      //Deserialize JSON string
                                      //JavaScriptSerializer class is in System.Web.Script.Serialization
                                      JavaScriptSerializer json = new JavaScriptSerializer();
                                      Datasets datasets = (Datasets)json.Deserialize(responseContent, typeof(Datasets));
                  
                                      resultsTextbox.Text = string.Empty;
                                      //Get each Dataset from 
                                      foreach (dataset ds in datasets.value)
                                      {
                                          resultsTextbox.Text += String.Format("{0}	{1}
                  ", ds.Id, ds.Name);
                                      }
                                  }
                              }
                          }
                          catch (WebException wex)
                          {
                              resultsTextbox.Text = wex.Message;
                          }
                      }
                  

                  推荐答案

                  尝试更改资源 URI:

                  Try changing the resource URI:

                  var result = authenticationContext.AcquireToken(resource: "https://management.core.windows.net/", clientCredential: credential);
                  

                  var result = authenticationContext.AcquireToken(resource: **"https://analysis.windows.net/powerbi/api"**, clientCredential: credential);
                  

                  您想为 power bi api 获取令牌.

                  You want to acquire a token for the power bi api.

                  希望有所帮助.

                  根据 OP 评论编辑更新答案:

                  这是你需要做的.

                  在 Azure AD 中创建一个本机应用程序"并获取该客户端 ID,不会有任何秘密.

                  In Azure AD create a "Native App" and get that client ID there will be NO Secret.

                  确保您拥有来自 Nuget Active Directory 身份验证库 2.23.302261847 的最新版本的 ADAL

                  Make sure you have the latest version of ADAL from Nuget Active Directory Authentication Library 2.23.302261847

                  您将需要使用此 Acquire Token Overload:

                  You will need to use this Acquire Token Overload:

                  authContext.AcquireToken("https://analysis.windows.net/powerbi/api", clientID, new UserCredential(<Username>, <Password>));
                  

                  2016-11-11

                  ADAL 3.13.7 UserCredentail 不再具有上述定义的构造函数.有一个新的密封类 UserPasswordCredential

                  ADAL 3.13.7 UserCredentail no longer has a constructor as defined above. There is a new sealed class UserPasswordCredential

                  public sealed class UserPasswordCredential : UserCredential
                  

                  哪个构造函数与之前的 UserCredential 对象相匹配

                  Which has the constructor that matches the former UserCredential object

                  public UserPasswordCredential(string userName, string password)
                  

                  您可以通过以下方式获取令牌:

                  You can acquire the token by doing this:

                  authContext.AcquireToken("https://analysis.windows.net/powerbi/api", clientID, new UserPasswordCredential(<Username>, <Password>));
                  

                  这篇关于如何使用非交互式身份验证连接到 Power BI API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:是否有 PBix 文件格式的文档/API? 下一篇:如何使用 C# 以编程方式编辑 Power BI Desktop 文档参

                  相关文章

                  最新文章

                  <legend id='oGBU6'><style id='oGBU6'><dir id='oGBU6'><q id='oGBU6'></q></dir></style></legend>

                  <small id='oGBU6'></small><noframes id='oGBU6'>

                  • <bdo id='oGBU6'></bdo><ul id='oGBU6'></ul>
                  <i id='oGBU6'><tr id='oGBU6'><dt id='oGBU6'><q id='oGBU6'><span id='oGBU6'><b id='oGBU6'><form id='oGBU6'><ins id='oGBU6'></ins><ul id='oGBU6'></ul><sub id='oGBU6'></sub></form><legend id='oGBU6'></legend><bdo id='oGBU6'><pre id='oGBU6'><center id='oGBU6'></center></pre></bdo></b><th id='oGBU6'></th></span></q></dt></tr></i><div id='oGBU6'><tfoot id='oGBU6'></tfoot><dl id='oGBU6'><fieldset id='oGBU6'></fieldset></dl></div>

                      <tfoot id='oGBU6'></tfoot>