Quantcast
Channel: Developer topics
Viewing all articles
Browse latest Browse all 17905

Generate Embed Token For Create Issue

$
0
0
Hello.
I have an issue with getting embed token. I've done what's described in this link (https://powerbi.microsoft.com/en-us/documentation/powerbi-developer-walkthrough-push-data/) and everything works perfectly: datasets creates, tables creates and fills with data without any problems.
I have a task to embed a datasets (not reports) to web page and here I'm getting an error.
I found this page (https://microsoft.github.io/PowerBI-JavaScript/demo/v2-demo/index.html) which shows how embed report/dataset/dashboard/tile will look like. And on this page there is an embed token.
I googled a little and found this page (https://msdn.microsoft.com/library/mt784614.aspx) which describes the looks oh HTTP POST requests. I did the part for datasets. Here is my code example:
 
 
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());            }        }
 
and I got next issue:
 
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
 
line 388 here:
 
EmbedToken token = powerBIclient.Reports.GenerateTokenForCreate(requestParameters);
 
I don't know why it's happening.
I got this code from here (https://msdn.microsoft.com/library/mt784614.aspx), but I did some changes for my purposes (because I need dataset and not report).
 
I'll appreciate any help.

 


Viewing all articles
Browse latest Browse all 17905

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>