(403)访问https://api.powerbi.com/v1.0/myorg/datasets PowerBI时出现禁止错误

时间:2017-01-31 04:54:25

标签: powerbi powerbi-datasource

我从PowerBi获得了授权令牌,在请求数据集时,我收到403错误。我可以用Apiary验证这项工作并返回结果。这是一个Windows窗体应用程序。 我的代码集如下

 string clientID = "{My App Client ID}";
 string redirectUri = "https://login.live.com/oauth20_desktop.srf";
 string resourceUri = "https://analysis.windows.net/powerbi/api";
 string authorityUri = "https://login.microsoftonline.com/{MyID}/oauth2/token";
 AuthenticationContext authContext = new   AuthenticationContext(authorityUri);
 AuthenticationResult result = null;
 ClientCredential cc = new ClientCredential(clientID, "{secret}");
 result = await authContext.AcquireTokenAsync(resourceUri, cc);
 token = result.AccessToken;

 string powerBIApiUrl =  "https://api.powerbi.com/v1.0/myorg/datasets";
 HttpWebRequest request = System.Net.WebRequest.Create(powerBIApiUrl) as     System.Net.HttpWebRequest;
 request.KeepAlive = true;
 request.Method = "GET";
 request.ContentLength = 0;
 request.ContentType = "application/json";
 request.Headers.Add("Authorization", String.Format("Bearer {0}", token));
  using (HttpWebResponse httpResponse = request.GetResponse() as System.Net.HttpWebResponse)
  {
    using (StreamReader reader = new System.IO.StreamReader(httpResponse.GetResponseStream()))
    {
       string responseContent = reader.ReadToEnd();
       JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
       Datasets datasets = (Datasets)JsonConvert.DeserializeObject(responseContent, typeof(Datasets));
       return datasets.value;
     }
   }

0 个答案:

没有答案