为创建问题生成嵌入令牌
Generate Embed Token For Create Issue
我在获取嵌入令牌时遇到问题。我已经完成了此 link (5 steps to push data into a dataset) 中描述的所有 5 个步骤,并且一切正常:数据集已创建,表格已创建并用数据填充,没有任何问题。
我的任务是将数据集(不是报告)嵌入网页。
我找到了这个页面 (Power BI Embeded Sample),它展示了嵌入 report/dataset/dashboard/tile 的样子。在此页面上有一个嵌入令牌。
我用谷歌搜索了一下,找到了这个页面 (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) 获取了这段代码,但出于我的目的做了一些更改(因为我需要数据集而不是报告)。
如有任何帮助,我将不胜感激。
我在尝试使用 Power BI 嵌入时遇到了类似的错误。我建议使用像 Fiddler 这样的工具来拦截您的应用程序和 Power BI 之间的通信,并找出实际返回的错误代码。
Telerik 的以下文章展示了如何使用 Fiddler 拦截流量:Capturing Traffic from .NET Services with Fiddler
我在获取嵌入令牌时遇到问题。我已经完成了此 link (5 steps to push data into a dataset) 中描述的所有 5 个步骤,并且一切正常:数据集已创建,表格已创建并用数据填充,没有任何问题。
我的任务是将数据集(不是报告)嵌入网页。 我找到了这个页面 (Power BI Embeded Sample),它展示了嵌入 report/dataset/dashboard/tile 的样子。在此页面上有一个嵌入令牌。 我用谷歌搜索了一下,找到了这个页面 (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) 获取了这段代码,但出于我的目的做了一些更改(因为我需要数据集而不是报告)。
如有任何帮助,我将不胜感激。
我在尝试使用 Power BI 嵌入时遇到了类似的错误。我建议使用像 Fiddler 这样的工具来拦截您的应用程序和 Power BI 之间的通信,并找出实际返回的错误代码。
Telerik 的以下文章展示了如何使用 Fiddler 拦截流量:Capturing Traffic from .NET Services with Fiddler