尝试获取Power Bi Client未经授权的访问令牌 [英] Trying to get access token for power bi client getting unauthorized
问题描述
使用(HttpClient客户端=新的HttpClient())
{
var tokenEndpoint = @" https://login.microsoftonline.com/c76b2843-f664-4aea-b02e-5b8c4e69e69d/oauth2/token;
var accept =" application/json" ;;
client.DefaultRequestHeaders.Add("Accept",accept);
字符串postBody = @"资源= https://analysis.windows.net/powerbi/api
& client_id = dbfcd775-c0f0-4058-b556-45dc8f47bc55
& client_secret = xrkf61T3nUz6WsqWf0Q1XYq + B1R3UblWHpL0XW6Of84 =
& grant_type =密码
& username=sudheerM@TODASSS.onmicrosoft.com
& password =<密码>
& scope = openid;
使用(var response = await client.PostAsync(tokenEndpoint,new StringContent(postBody,Encoding.UTF8,"application/x-www-form-urlencoded")))
{
如果(response.IsSuccessStatusCode)
{
var jsonresult = JObject.Parse(等待response.Content.ReadAsStringAsync());
var stoken =(string)jsonresult ["access_token"];
}
}
}
using (HttpClient client = new HttpClient())
{
var tokenEndpoint = @"https://login.microsoftonline.com/c76b2843-f664-4aea-b02e-5b8c4e69e69d/oauth2/token";
var accept = "application/json";
client.DefaultRequestHeaders.Add("Accept", accept);
string postBody = @"resource=https://analysis.windows.net/powerbi/api
&client_id=dbfcd775-c0f0-4058-b556-45dc8f47bc55
&client_secret=xrkf61T3nUz6WsqWf0Q1XYq+B1R3UblWHpL0XW6Of84=
& grant_type=password
&username=sudheerM@TODASSS.onmicrosoft.com
&password=<password>
&scope=openid";
using (var response = await client.PostAsync(tokenEndpoint, new StringContent(postBody, Encoding.UTF8, "application/x-www-form-urlencoded")))
{
if (response.IsSuccessStatusCode)
{
var jsonresult = JObject.Parse(await response.Content.ReadAsStringAsync());
var stoken = (string)jsonresult["access_token"];
}
}
}
推荐答案
我相信您会收到此错误,因为您传递的用户名/密码无权访问Power BI.请确保将PowerBI凭据(帐户用户名和密码)传递到REST API端点.
I believe you are getting this error as the username/password which you are passing does not have access to Power BI. Please make sure that you are passing the PowerBI Credentials (Account User Name and Password) to REST API end point.
这篇关于尝试获取Power Bi Client未经授权的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!