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?