我一直在尝试运行一个简单的测试。连接到本机AAD令牌并读取Power BI租户上的仪表板列表的控制台应用程序。现在已经一天了,一旦发送到Power BI API的请求,我就被困在403上。我有一个控制台应用程序和Postman ...结果相同。
请帮助。这是控制台应用程序。
static void Main(string[] args)
{
tokenString = GetToken();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://api.powerbi.com/v1.0/myorg/groups");
request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
request.Headers.Add("Authorization", String.Format("Bearer {0}", tokenString));
request.Method = "GET";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
var x = reader.ReadToEnd();
}
}
#region Get an authentication access token
private static string GetToken()
{
string clientID = "f6e83929-565c-4200-b75e-5a61b38c5633";
string redirectUri = "https://dev.powerbi.com/Apps/SignInRedirect";
string resourceUri = "f6e83929-565c-4200-b75e-5a61b38c5633";
string authorityUri = "https://login.microsoftonline.com/<My Tenant ID>/oauth2/authorize";
AuthenticationContext authContext = new AuthenticationContext(authorityUri);
string token = authContext.AcquireToken(resourceUri, clientID, new Uri(redirectUri)).AccessToken;
Console.WriteLine(token);
return token;
}
#endregion
}
答案 0 :(得分:0)
对于发现此问题的任何人,我经过3天的阅读后都找到了答案。
似乎完全是“ https://analysis.windows.net/powerbi/api ”,而不是应用程序资源,也不是上面更新的api url。更改它,一切正常