我有一个获取嵌入令牌的问题。我已经完成了这个链接(5 steps to push data into a dataset)中描述的全部5个步骤,并且一切都很完美:创建数据集,创建表格并填充数据,没有任何问题。生成嵌入令牌创建问题
我有一个任务嵌入数据集(不报告)到网页。 我发现这个页面(Power BI Embeded Sample),它显示了嵌入report/dataset/dashboard/tile的样子。在这个页面上有一个嵌入标记。 我GOOGLE了一下,发现这个页面(Generate Embed Token Example),它描述了HTTP POST请求的外观。我为数据集做了部分。这里是我的代码示例:
private static void generateEmbedToken()
{
// TokenCredentials Initializes a new instance of the
// Microsoft.Rest.TokenCredentials class with
// the given 'Bearer' token.
var credentials = new TokenCredentials(token);
// Initialize PowerBIClient with credentials
var powerBIclient = new Microsoft.PowerBI.Api.V2.PowerBIClient(credentials)
{
// BaseUri is the api endpoint, default is https://api.powerbi.com
BaseUri = new Uri("https://api.powerbi.com")
};
try
{
// Create body where accessLevel = View, datasetId = "" by default
var requestParameters = new GenerateTokenRequest(TokenAccessLevel.Create, datasetId, true);
// Generate EmbedToken This function sends the POST message
//with all parameters and returns the token
EmbedToken token = powerBIclient.Reports.GenerateTokenForCreate(requestParameters);
embedToken = token.Token;
}
catch (Exception exc)
{
Console.WriteLine(exc.ToString());
}
}
,我得到了一个错误:
Microsoft.Rest.HttpOperationException: Operation returned an invalid status code 'NotFound'
at Microsoft.PowerBI.Api.V2.Reports.<GenerateTokenForCreateWithHttpMessagesAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.V2.ReportsExtensions.<GenerateTokenForCreateAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.PowerBI.Api.V2.ReportsExtensions.GenerateTokenForCreate(IReports operations, GenerateTokenRequest requestParameters)
at PushDataApp.Program.generateEmbedToken() in C:\Users\PC\Documents\Visual Studio 2017\Projects\PushDataApp\PushDataApp\Program.cs:line 388
这里是行388:
EmbedToken token = powerBIclient.Reports.GenerateTokenForCreate(requestParameters);
我不知道为什么它的发生。 我从这里取得这段代码(Generate Embed Token Example),但为了我的目的我做了一些改变(因为我需要数据集而不报告)。
我会很感激任何帮助。