Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Signon Troubles UriFormatException: Invalid URI: The hostname could not be parsed

Found some discussion but was all on Wepapp.

In a simple console app I would like to conect the PBI API, but i'm keep running into this error.

UriFormatException: Invalid URI: The hostname could not be parsed.

This is the very basic code ...

        private static string clientId = "Key-received-by-creating-the-app-with-pbi-portal";
        private static string ResourceUrl = @"https://analysis.windows.net/powerbi/api";
        private static string AuthorityUrl = @"https://login.windows.net/common/oauth2/authorize";
        private static string ApiUrl = @"https://api.powerbi.com/";
        private static string token;
        private static PowerBIClient pbiClient;

        static void Main(string[] args)
        {
            Console.WriteLine("Connecting ...");
            pbiClient = GetToken();
            Console.WriteLine("Conneced.");
            Console.ReadKey();
        }

        private static PowerBIClient GetToken()
        {
            var credential = new UserPasswordCredential("[email protected]", "xyz");
            var authenticationContext = new AuthenticationContext(AuthorityUrl, false);
            var authenticationResult = authenticationContext.AcquireTokenAsync(ResourceUrl, clientId, credential).Result;
            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");
            var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials);

            return client;
        }

If somebody could give me a hand, i'm not a C# developper, but would like to create a simple program to define py push datasets.

 

Kind regards, Harry

No Replies