I'm getting this error while trying to run my c# console application... I am trying to call google calender api v3 to fetch calender and add event to calender. According to the sample code from google-api-dotnet-client I am doing this.( https://code.google.com/p/google-api-dotnet-client/source/browse/Calendar.VB.ConsoleApp/Program.vb?repo=samples ) Here is the vb.net code. I am using this sample after converting it to c# code.
Here is my code:
class Program
{
static void Main(string[] args)
{
try
{
new Program().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("ERROR: " + e.Message);
}
}
}
private async Task Run()
{
UserCredential credential;
IList<string> scopes = new List<string>();
CalendarService service;
scopes.Add(CalendarService.Scope.Calendar);
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
// problem occuring during executing this statement.
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user", CancellationToken.None, new FileDataStore("Calender.SampleApp") );
}
BaseClientService.Initializer initializer = new BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
initializer.ApplicationName = "C# Calendar Sample";
service = new CalendarService(initializer);
Event newEvent = new Event();
newEvent.Summary = "Appointment";
newEvent.Description = "Need to meet my Uncle";
IList<EventReminder> reminders = new List<EventReminder>();
reminders.Add(new EventReminder { Method = "sms", Minutes = 10 });
newEvent.Reminders = new Event.RemindersData { UseDefault = false, Overrides = reminders };
newEvent.Recurrence = new String[] { "DTSTART;TZID=Bangladesh Standard Time:20140124T163000;RRULE:FREQ=DAILY" };
IList<EventAttendee> attendees = new List<EventAttendee>();
attendees.Add(new EventAttendee { Email = "[email protected]", Organizer = true, DisplayName = "Hannan" });
newEvent.Attendees = attendees;
newEvent.GuestsCanInviteOthers = false;
newEvent.GuestsCanModify = false;
newEvent.GuestsCanSeeOtherGuests = false;
newEvent.Location = "Dhaka, Bangladesh";
newEvent.Start = new EventDateTime { DateTime = DateTime.Now, TimeZone = "Bangladesh Standard Time" };
Event recurringEvent = service.Events.Insert(newEvent, "primary").Execute();
var list = await service.CalendarList.List().ExecuteAsync();
}
}
This is my redirect URIs in my GoogleDevelopers Console project.
Redirect URIs: http://localhost:7744/authorize/
And this is the error message shown in browser.
I couldn't find any way to resolve this problem. Some help will be appreciable. I also search all the realted post in stackoverflow. But I couldn't find it's solution.
According to request type you must create clientid and credintials in your registered application in Google Developers Console. You don't need to define redirect uri in console application while authenticating. Show activity on this post.
The redirect URIs are in the client_secrets.jsonfile for multiple reasons ... one big one is so that the oAuth flow can verify that the redirect your app specifies matches what your app allows.
Error: redirect_uri_mismatch In Google Login in MVC Application The redirect URI you set in Google Developer console must exactly match where you are sending the request from. If you notice the Port number is changing. This is because visual studio has a habit of adding random port numbers when you are debugging via visual stuido.
In order to use the downloaded example, these two URIs have to be: This is absolutely not working for us. We need to be able to set them to different ones, for example …/home/index.
I think you are doing something wrong while "create client id" in GoogleDevelopers Console. Make sure that you have chosed "Installed application" in application type to access your project from console application.
Have a look in the attached image. According to request type you must create clientid and credintials in your registered application in Google Developers Console.
You don't need to define redirect uri in console application while authenticating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With