Reputation: 1002
I am wondering if anyone can assist me, I am having a problem with power bi. What I am trying to do is push some data into Power BI. I am finding it difficult to find an approach were a user can enter there user name and password and then I will be able to push data into the Power BI account.
I am getting stuck at the first hurdle of getting an Access Token. I just keeping bad request. I have also tried getting-started-for-dotnet which for some strange reason I can also not get to work.
Error given is: The remote server returned an error: (401) Unauthorized.
Registered as Web application
public class PowerBICreds
{
public string resourceUri { get; set; }
public string clientID { get; set; }
public string grantType { get; set; }
public string username { get; set; }
public string password { get; set; }
public string scope { get; set; }
public string clientSecret { get; set; }
public string loginAddress { get; set; }
public string baseurl { get; set; }
}
public static string AccessToken(PowerBICreds Creds)
{
StringBuilder Httpbody = new StringBuilder();
Httpbody.Append("resource=" + HttpUtility.UrlEncode(Creds.resourceUri));
Httpbody.Append("&client_id=" + HttpUtility.UrlEncode(Creds.clientID));
Httpbody.Append("&grant_type=" + HttpUtility.UrlEncode(Creds.grantType));
Httpbody.Append("&username=" + HttpUtility.UrlEncode(Creds.username));
Httpbody.Append("&password=" + HttpUtility.UrlEncode(Creds.password));
Httpbody.Append("&scope=" + HttpUtility.UrlEncode(Creds.scope));
Httpbody.Append("&client_secret=" + HttpUtility.UrlEncode(Creds.clientSecret));
using (WebClient web = new WebClient())
{
web.Headers.Add("client-request-id", Guid.NewGuid().ToString());
web.Headers.Add("return-client-request-id", "true");
string jsonstring = web.UploadString(Creds.loginAddress, Httpbody.ToString());
dynamic result = JsonConvert.DeserializeObject(jsonstring);
try
{
return result.access_token;
}
catch
{
}
return null;
}
}
Update when I try the sample to show how to use the Power BI API provided by Mircosoft here https://github.com/PowerBI/getting-started-for-dotnet
Additional technical information: Correlation ID: f1281ec2-4e09-41e6-8847-3acfd3eb7922 Timestamp: 2015-12-04 22:48:58Z AADSTS65005: The client application has requested access to resource 'https://analysis.windows.net/powerbi/api'. This request has failed because the client has not specified this resource in its requiredResourceAccess list.
Upvotes: 2
Views: 2570
Reputation: 366
The error you got when using our sample application may mean that the app you registered with AAD doesn't request any permission for Power BI. Try using our new app registration page at http://dev.powerbi.com/apps. If you just want to push data into Power BI, you just need the dataset read/write permission.
Upvotes: 4