"Failed to launch browser with \"https://accounts.google.com/o/oauth2/v2

Siwar Ha

Member
Joined
May 28, 2021
Messages
5
Programming Experience
Beginner
C#:
        public static DriveService Execution(string ApplicationName, string credentials)
        {
            UserCredential credential;

            using (var stream =
                new FileStream(credentials, FileMode.Open, FileAccess.Read))
            {

                string credPath = "token.json";

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                            GoogleClientSecrets.Load(stream).Secrets,
                            Scopes,
                            "XXXX",
                            CancellationToken.None,
                            new FileDataStore(credPath, true)).Result;
            }
            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });

            return service;
        }


I know that i have to replace GoogleWebAuthorizationBroker with GoogleAuthorizationCodeFlow but i didnt get what should REFRESH_TOKEN get like value ?
any help please ?
 
C#:
        public static DriveService Execution(string ApplicationName, string credentials)
        {
            var clientSecrets = new ClientSecrets
            {
                ClientId = "xxxx",
                ClientSecret = "xxxx"
            };

            var credential = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
            {
                ClientSecrets = clientSecrets,
                Scopes =Scopes
            });
            // Create Drive API service.
            var service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer =// I HAVE A PROBLEM HERE
                ApplicationName = ApplicationName,
            });

            return service;
        }


WHAT I have to put in HttpClientInitializer ? because i used to use GoogleWebAuthorizationBroker and it accept credential like a value
 
And?

You are only passing two of the three required parameters.

because i used to use GoogleWebAuthorizationBroker and it accept credential like a value

What value? Values can be of different types...

This should be moved to third party. It's a Google API question non specific to C#.
 
Back
Top Bottom