C Google Calendar: List Events on a Calendar

Back to Index

Returns events on the specified calendar.
This example returns the events for the calendar having the ID = "support@chilkatcloud.com"

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/list


#include <C_CkRest.h>
#include <C_CkOAuth2.h>
#include <C_CkStringBuilder.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkOAuth2 oauth2;
    HCkStringBuilder sbJson;
    HCkJsonObject json;
    const char *kind;
    const char *etag;
    const char *summary;
    const char *updated;
    const char *timeZone;
    const char *accessRole;
    const char *nextSyncToken;
    int i;
    int count_i;
    const char *method;
    int minutes;
    const char *id;
    const char *status;
    const char *htmlLink;
    const char *created;
    const char *creatorEmail;
    BOOL creatorSelf;
    const char *organizerEmail;
    BOOL organizerSelf;
    const char *startDateTime;
    const char *endDateTime;
    const char *iCalUID;
    int sequence;
    const char *hangoutLink;
    BOOL remindersUseDefault;
    const char *location;

    rest = CkRest_Create();

    //   Provide a previously obtained OAuth2 access token.
    oauth2 = CkOAuth2_Create();
    CkOAuth2_putAccessToken(oauth2,"OAUTH2_ACCESS_TOKEN");
    CkRest_SetAuthOAuth2(rest,oauth2);

    success = CkRest_Connect(rest,"www.googleapis.com",443,TRUE,TRUE);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkOAuth2_Dispose(oauth2);
        return;
    }

    sbJson = CkStringBuilder_Create();
    success = CkRest_FullRequestNoBodySb(rest,"GET","/calendar/v3/calendars/support@chilkatcloud.com/events",sbJson);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkOAuth2_Dispose(oauth2);
        CkStringBuilder_Dispose(sbJson);
        return;
    }

    if (CkRest_getResponseStatusCode(rest) != 200) {
        printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest));
        printf("Response body:\n");
        printf("%s\n",CkStringBuilder_getAsString(sbJson));
        CkRest_Dispose(rest);
        CkOAuth2_Dispose(oauth2);
        CkStringBuilder_Dispose(sbJson);
        return;
    }

    json = CkJsonObject_Create();
    CkJsonObject_LoadSb(json,sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.

    kind = CkJsonObject_stringOf(json,"kind");
    etag = CkJsonObject_stringOf(json,"etag");
    summary = CkJsonObject_stringOf(json,"summary");
    updated = CkJsonObject_stringOf(json,"updated");
    timeZone = CkJsonObject_stringOf(json,"timeZone");
    accessRole = CkJsonObject_stringOf(json,"accessRole");
    nextSyncToken = CkJsonObject_stringOf(json,"nextSyncToken");
    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"defaultReminders");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        method = CkJsonObject_stringOf(json,"defaultReminders[i].method");
        minutes = CkJsonObject_IntOf(json,"defaultReminders[i].minutes");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"items");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        kind = CkJsonObject_stringOf(json,"items[i].kind");
        etag = CkJsonObject_stringOf(json,"items[i].etag");
        id = CkJsonObject_stringOf(json,"items[i].id");
        status = CkJsonObject_stringOf(json,"items[i].status");
        htmlLink = CkJsonObject_stringOf(json,"items[i].htmlLink");
        created = CkJsonObject_stringOf(json,"items[i].created");
        updated = CkJsonObject_stringOf(json,"items[i].updated");
        summary = CkJsonObject_stringOf(json,"items[i].summary");
        creatorEmail = CkJsonObject_stringOf(json,"items[i].creator.email");
        creatorSelf = CkJsonObject_BoolOf(json,"items[i].creator.self");
        organizerEmail = CkJsonObject_stringOf(json,"items[i].organizer.email");
        organizerSelf = CkJsonObject_BoolOf(json,"items[i].organizer.self");
        startDateTime = CkJsonObject_stringOf(json,"items[i].start.dateTime");
        endDateTime = CkJsonObject_stringOf(json,"items[i].end.dateTime");
        iCalUID = CkJsonObject_stringOf(json,"items[i].iCalUID");
        sequence = CkJsonObject_IntOf(json,"items[i].sequence");
        hangoutLink = CkJsonObject_stringOf(json,"items[i].hangoutLink");
        remindersUseDefault = CkJsonObject_BoolOf(json,"items[i].reminders.useDefault");
        location = CkJsonObject_stringOf(json,"items[i].location");
        i = i + 1;
    }

    printf("Example Completed.\n");


    CkRest_Dispose(rest);
    CkOAuth2_Dispose(oauth2);
    CkStringBuilder_Dispose(sbJson);
    CkJsonObject_Dispose(json);

    }

Sample JSON Response Body

{
  "kind": "calendar#events",
  "etag": "\"p32gd13choqmte0g\"",
  "summary": "support@chilkatcloud.com",
  "updated": "2017-11-07T22:49:27.892Z",
  "timeZone": "America/Chicago",
  "accessRole": "owner",
  "defaultReminders": [
    {
      "method": "popup",
      "minutes": 10
    }
  ],
  "nextSyncToken": "CKDQjZHGrdcCEKDQjZHGrdcCGAU=",
  "items": [
    {
      "kind": "calendar#event",
      "etag": "\"3004746854620000\"",
      "id": "5jt9fopfg3rr9eftegiuq7gc5k",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NWp0OWZvcGZnM3JyOWVmdGVnaXVxN2djNWsgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:07.000Z",
      "updated": "2017-08-10T13:57:07.310Z",
      "summary": "Run 10 miles",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T13:00:00-05:00"
      },
      "iCalUID": "5jt9fopfg3rr9eftegiuq7gc5k@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.5jt9fopfg3rr9eftegiuq7gc5k",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004746898118000\"",
      "id": "7dvh49vd219r3sq7jdueieu8rc",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=N2R2aDQ5dmQyMTlyM3NxN2pkdWVpZXU4cmMgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:29.000Z",
      "updated": "2017-08-10T13:57:29.059Z",
      "summary": "Eat Giordano's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T15:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T16:00:00-05:00"
      },
      "iCalUID": "7dvh49vd219r3sq7jdueieu8rc@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.7dvh49vd219r3sq7jdueieu8rc",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004746915224000\"",
      "id": "5btd89ljn07bg3tlgpimcaqrro",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NWJ0ZDg5bGpuMDdiZzN0bGdwaW1jYXFycm8gc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-10T13:57:37.000Z",
      "updated": "2017-08-10T13:57:37.612Z",
      "summary": "Nap",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-10T16:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-10T17:30:00-05:00"
      },
      "iCalUID": "5btd89ljn07bg3tlgpimcaqrro@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.5btd89ljn07bg3tlgpimcaqrro",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915127736000\"",
      "id": "703fss5qdedn1egq80ildhslba",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NzAzZnNzNXFkZWRuMWVncTgwaWxkaHNsYmEgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:23.000Z",
      "updated": "2017-08-11T13:19:23.868Z",
      "summary": "Run 12 miles",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T09:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T10:30:00-05:00"
      },
      "iCalUID": "703fss5qdedn1egq80ildhslba@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.703fss5qdedn1egq80ildhslba",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915160212000\"",
      "id": "02pv1cpdp7vm11htnfi3ii7iie",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MDJwdjFjcGRwN3ZtMTFodG5maTNpaTdpaWUgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:40.000Z",
      "updated": "2017-08-11T13:19:40.106Z",
      "summary": "Eat Lou Malnati's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T13:00:00-05:00"
      },
      "iCalUID": "02pv1cpdp7vm11htnfi3ii7iie@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.02pv1cpdp7vm11htnfi3ii7iie",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004915175982000\"",
      "id": "20l29s2idr5ggorncd3teahm0e",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MjBsMjlzMmlkcjVnZ29ybmNkM3RlYWhtMGUgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T13:19:47.000Z",
      "updated": "2017-08-11T13:19:47.991Z",
      "summary": "Nap",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T16:30:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T17:30:00-05:00"
      },
      "iCalUID": "20l29s2idr5ggorncd3teahm0e@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.20l29s2idr5ggorncd3teahm0e",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3004969011208000\"",
      "id": "v7kvmsvsoms3hjl5uq423jqhb0",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=djdrdm1zdnNvbXMzaGpsNXVxNDIzanFoYjAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-08-11T20:48:25.000Z",
      "updated": "2017-08-11T20:48:25.604Z",
      "summary": "Eat Lou Malnati's Pizza",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-08-12T12:00:00-05:00"
      },
      "end": {
        "dateTime": "2017-08-12T13:00:00-05:00"
      },
      "iCalUID": "v7kvmsvsoms3hjl5uq423jqhb0@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.v7kvmsvsoms3hjl5uq423jqhb0",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007268672000\"",
      "id": "1p7fb5vob7vm57fepk4p1teft9",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MXA3ZmI1dm9iN3ZtNTdmZXBrNHAxdGVmdDkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:27:14.000Z",
      "updated": "2017-11-06T21:27:14.336Z",
      "summary": "Breakfast at Tiffany's",
      "location": "Tiffany's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T07:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T08:00:00-06:00"
      },
      "iCalUID": "1p7fb5vob7vm57fepk4p1teft9@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.1p7fb5vob7vm57fepk4p1teft9",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007309018000\"",
      "id": "05f5eieun35hoofbiab00ru03o",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MDVmNWVpZXVuMzVob29mYmlhYjAwcnUwM28gc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:27:34.000Z",
      "updated": "2017-11-06T21:27:34.509Z",
      "summary": "Lunch at Sushi House",
      "location": "Sushi House",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T12:30:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T13:30:00-06:00"
      },
      "iCalUID": "05f5eieun35hoofbiab00ru03o@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.05f5eieun35hoofbiab00ru03o",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007516220000\"",
      "id": "4hrv7chnc3jspepqr4ntrsq6k9",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NGhydjdjaG5jM2pzcGVwcXI0bnRyc3E2azkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:29:17.000Z",
      "updated": "2017-11-06T21:29:18.110Z",
      "summary": "Dinner at Gia Mia",
      "location": "Gia Mia",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-06T19:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-06T20:00:00-06:00"
      },
      "iCalUID": "4hrv7chnc3jspepqr4ntrsq6k9@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.4hrv7chnc3jspepqr4ntrsq6k9",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007580384000\"",
      "id": "53k665tdurv5geejkl8d9eljmp",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NTNrNjY1dGR1cnY1Z2VlamtsOGQ5ZWxqbXAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:29:50.000Z",
      "updated": "2017-11-06T21:29:50.192Z",
      "summary": "Breakfast at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T07:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T08:00:00-06:00"
      },
      "iCalUID": "53k665tdurv5geejkl8d9eljmp@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.53k665tdurv5geejkl8d9eljmp",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007628078000\"",
      "id": "27n9mbbabkur965n87ddir6m1i",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=MjduOW1iYmFia3VyOTY1bjg3ZGRpcjZtMWkgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:30:14.000Z",
      "updated": "2017-11-06T21:30:14.039Z",
      "summary": "Lunch at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T13:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T14:00:00-06:00"
      },
      "iCalUID": "27n9mbbabkur965n87ddir6m1i@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.27n9mbbabkur965n87ddir6m1i",
      "reminders": {
        "useDefault": true
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020007645098000\"",
      "id": "3jmu86tk17hc21gam5l073pu1k",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=M2ptdTg2dGsxN2hjMjFnYW01bDA3M3B1MWsgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
      "created": "2017-11-06T21:30:22.000Z",
      "updated": "2017-11-06T21:30:22.549Z",
      "summary": "Dinner at McDonald's",
      "location": "McDonald's",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-09T19:00:00-06:00"
      },
      "end": {
        "dateTime": "2017-11-09T20:00:00-06:00"
      },
      "iCalUID": "3jmu86tk17hc21gam5l073pu1k@google.com",
      "sequence": 0,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.3jmu86tk17hc21gam5l073pu1k",
      "reminders": {
        "useDefault": true
      }
    }
  ]
}