-1

I have written some code to export appointments from my desktop C# application to Google Calendar. I am using Google Calendar API for .NET.

The code works well, except for the web browser always shows an error page after authentication (the authentication is always successfull, despite this). This is the message I see: "could not connect. Firefox could not stablish a connection to server in localhost:xxx (any port)". It happens in every browser.

I have created my credentials in Google Console with this parameters: - using Google Calendar API; - calling API from other UI (NOT web server) - access to user data.

This is my code:

public static CalendarService GetCalendarService(String[] Scopes, String userNameGoogle, String ApplicationName)
    {
        UserCredential credential;

        using (var stream =
            new FileStream("credentials.json", FileMode.Open, FileAccess.Read))
        {
            string credPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
            credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");
            //MessageBox.Show(credPath);

            credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                GoogleClientSecrets.Load(stream).Secrets,
                Scopes,
                userNameGoogle,
                CancellationToken.None,
                new FileDataStore(credPath, true)).Result;

            //MessageBox.Show("Credential file saved to: " + credPath);

        }

            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });

            return service;
    } 

This is what happens when authenticating: See Authenticating Image

... and after that, the redirection error: See Redirection error Image

I have spent hours and hours reading posts, but no results (almost everybody is using web server, but not my case).

Please, could you help me?

David
  • 11
  • 1

2 Answers2

1

Finally, after so many days spent I got the answer: the problem was the antivirus software (Kaspersky free version).

The three computers I have used to test had the same antivirus. After disabling it, the web browsers are redirecting well. My apologies for not testing it before.

I apreciate your answers (@mjwills, @Chris, @u_1826). Thank you very much. I hope this information helps others.

David
  • 11
  • 1
-2

the path you have put as callback url http://localhost:6773/ exists?

u_1826
  • 57
  • 2
  • 14
  • What wrong i said? see his screeshot, from google its returning back to local address. or go ahead answer him – u_1826 Aug 06 '18 at 12:32