public void Authentication(Ctx ctx) { var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = ClientCredentials.ClientID; provider.ClientSecret = ClientCredentials.ClientSecret; // Create the service. This will automatically call the authenticator. if (isTask) { var service = new TasksService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); Google.Apis.Tasks.v1.TasklistsResource.ListRequest clrq = service.Tasklists.List(); clrq.MaxResults = "1000"; TaskLists taskslist = clrq.Fetch(); FetchingTasks(service, taskslist, ctx); } else { var service = new CalendarService(new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication)); Google.Apis.Calendar.v3.CalendarListResource.ListRequest clrq = service.CalendarList.List(); var result = clrq.Fetch(); FetchingCalendar(result, service, ctx); } }
public static void Main(string[] args) { // Register the authenticator. The Client ID and secret have to be copied from the API Access // tab on the Google APIs Console. var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description); provider.ClientIdentifier = "84383943259-98qi37g6fubpvovgk51ckoab5op4g8t4.apps.googleusercontent.com"; provider.ClientSecret = "Sa1SX05WXwmtd1hMAzFcJFw2"; var auth = new OAuth2Authenticator <NativeApplicationClient>(provider, GetAuthentication); CalendarService service = new CalendarService(new BaseClientService.Initializer() { Authenticator = auth, GZipEnabled = false }); Google.Apis.Calendar.v3.CalendarListResource.ListRequest clrq = service.CalendarList.List(); var result = clrq.Execute(); Console.WriteLine("Calendars: "); DateTime lastPoll = DateTime.MinValue; var continue_poll = ""; do { foreach (CalendarListEntry calendar in result.Items) { Console.WriteLine("{0}", calendar.Id); Console.WriteLine("\tAppointments:"); //Google.Apis.Calendar.v3.EventsResource.ListRequest elr = service.Events.List(calendar.Id); //var events = elr.Execute(); var events = LoadCalendarEvent(service, calendar.Id, lastPoll); lastPoll = DateTime.Now; foreach (Event e in events.Items) { Console.WriteLine("\t From: {0} To: {1} Description: {2}, Location: {3}, Id: {4}", e.Start.DateTime, e.End.DateTime, e.Summary, e.Location, e.Id); } } Console.WriteLine("To continue press any key other than Q"); continue_poll = Console.ReadKey().KeyChar.ToString(); } while (continue_poll != "q"); }