1
我試圖嵌入使用this link.嵌入非PBI用戶雙向電力報告
提供在這個樣品的樣品一雙向電力報告到網頁,我已經取代我的親帳戶的所有客戶端ID和用戶名密碼。
我在應用程序註冊中設置了本機應用程序類型。當我試圖讓嵌入令牌,下面的錯誤來了:
這裏是我的代碼:
public async Task<ActionResult> EmbedReport()
{
// Create a user password credentials.
UserPasswordCredential UserCredentials = new UserPasswordCredential(Username, Password);
AuthenticationContext AuthContext = new AuthenticationContext(AuthorityUrl, false);
// Authenticate using created credentials
//AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, clientCred);
AuthenticationResult AuthResult = await AuthContext.AcquireTokenAsync(ResourceUrl, ClientId, UserCredentials);
if (AuthResult == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Authentication Failed."
});
}
var tokenCredentials = new TokenCredentials(AuthResult.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))
{
// Get a list of reports.
var reports = client.Reports.GetReports();
// Get the first report in the group.
var report = reports.Value.FirstOrDefault();
if (report == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Group has no reports."
});
}
string accessLevel = "View";
// Generate Embed Token.
var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel, report.DatasetId,false);
var tokenResponse = client.Reports.GenerateToken(report.Id, generateTokenRequestParameters);
if (tokenResponse == null)
{
return View(new EmbedConfig()
{
ErrorMessage = "Failed to generate embed token."
});
}
// Generate Embed Configuration.
var embedConfig = new EmbedConfig()
{
EmbedToken = tokenResponse,
EmbedUrl = report.EmbedUrl,
Id = report.Id
};
return View(embedConfig);
}
}
併爲其他人澄清...您以用戶身份登錄到門戶和「授予權限」作爲您想從應用程序「模擬」到Power BI的用戶。如果您實際上沒有通過GUI公開的AAD應用程序(這將允許您更自然地確認同意),您只需執行此操作。 – Jmoney38
只是另一個有用的參考,因爲這些東西可能很難診斷:https:// github.com/Microsoft/PowerBI-Developer-Samples/issues/19 – Jmoney38