首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >现在要求通过c#刷新power bi report 错误解决不了 azure和BI是中国版的 ?

现在要求通过c#刷新power bi report 错误解决不了 azure和BI是中国版的 ?

提问于 2019-06-25 11:29:07
回答 1关注 0查看 443

public ActionResult Index()

{

string AuthorityUrl = @"https://login.windows.net/common/oauth2/authorize";

string ResorceUrl = @"https://analysis.windows.net/powerbi/api";

string APIUrl = @"https://api.powerbi.cn";

string ClientId = "1950a258-227b-4e31-a9cf-717495945fc2";

string Account = "账号";

string Pwd = "密码";

string groupId = "2a8498b7-83d2-4913-af70-111867101fcb";

string datasetId = "2594184";

string result = Result(Account, Pwd, AuthorityUrl, ResorceUrl, APIUrl, ClientId, groupId, datasetId);

ViewBag.msg = result;

return View();

}

private string Result(string Username, string Password, string AuthorityUrl, string ResourceUrl, string ApiUrl, string ClientId, string GroupId, string DatasetId)

{

var credential = new UserPasswordCredential(Username, Password);

var authenticationContext = new AuthenticationContext(AuthorityUrl);

var authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential).Result;

if (authenticationResult == null)

{

return null;

}

var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

// Create a Power BI Client object. It will be used to call Power BI APIs.

using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))

{

string res = null;

// Get a list of reports.

HttpWebRequest request;

var url = "https://api.powerbi.com/v1.0/myorg/groups/{0}/datasets/{1}/refreshes";

request = HttpWebRequest.CreateHttp(string.Format(url, GroupId, DatasetId));

request.KeepAlive = true;

request.Method = "POST";

request.ContentLength = 0;

request.Headers.Add("Authorization", String.Format("Bearer {0}", authenticationResult.AccessToken));

using (Stream writer = request.GetRequestStream())

{

var response = (HttpWebResponse)request.GetResponse();

res += ("Dataset refresh request{0}", response.StatusCode.ToString());

}

return res;

}

}

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档