private void button2_Click_1(object sender, EventArgs e)
    {
        try
        {
            NativeApplicationClient client = new NativeApplicationClient(GoogleAuthenticationServer.Description, this.clientID, this.clientSecret);
            OAuth2Authenticator <NativeApplicationClient> auth = new OAuth2Authenticator <NativeApplicationClient>(client, Authenticate);
            // Authenticated and ready for API calls...

            // EITHER Calendar API calls (tested):
            CalendarService                     cal         = new CalendarService(auth);
            EventsResource.ListRequest          listrequest = cal.Events.List(this.primaryCal);
            Google.Apis.Calendar.v3.Data.Events events      = listrequest.Fetch();
            // iterate the events and show them here.
            // OR Plus API calls (not tested) - copied from OP's code:
            var plus = new PlusService(auth);
            plus.Key = "BLAH";                          // don't know what this line does.
            var me = plus.People.Get("me").Fetch();
            Console.WriteLine(me.DisplayName);

            // OR some other API calls...
        }
        catch (Exception ex)
        {
            Console.WriteLine("Error while communicating with Google servers. Try again(?). The error was:\r\n" + ex.Message + "\r\n\r\nInner exception:\r\n" + ex.InnerException.Message);
        }
    }
예제 #2
0
        public Google.Apis.Calendar.v3.Data.Events GetEvents()
        {
            UserCredential credential;

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

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;
                Console.WriteLine("Credential file saved to: " + credPath);
            }

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

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin      = DateTime.Now;
            request.ShowDeleted  = false;
            request.SingleEvents = true;
            request.MaxResults   = 10;
            request.OrderBy      = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            Google.Apis.Calendar.v3.Data.Events events = request.Execute();
            return(events);
        }
예제 #3
0
        public ActionResult CalendarEvents()
        {
            Google.Apis.Calendar.v3.Data.Events events = Calendar.GetCalendarEvents();

            return(PartialView(events));
        }