Unicode C Google Calendar: List Calendars

Back to Index

Returns entries on the user's calendar list.

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


#include <C_CkRestW.h>
#include <C_CkOAuth2W.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkOAuth2W oauth2;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    const wchar_t *kind;
    const wchar_t *etag;
    const wchar_t *nextSyncToken;
    int i;
    int count_i;
    const wchar_t *id;
    const wchar_t *summary;
    const wchar_t *timeZone;
    const wchar_t *colorId;
    const wchar_t *backgroundColor;
    const wchar_t *foregroundColor;
    BOOL selected;
    const wchar_t *accessRole;
    BOOL primary;
    int j;
    int count_j;
    const wchar_t *method;
    int minutes;
    const wchar_t *type;

    rest = CkRestW_Create();

    //   Provide a previously obtained OAuth2 access token.
    oauth2 = CkOAuth2W_Create();
    CkOAuth2W_putAccessToken(oauth2,L"OAUTH2_ACCESS_TOKEN");
    CkRestW_SetAuthOAuth2(rest,oauth2);

    success = CkRestW_Connect(rest,L"www.googleapis.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        return;
    }

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/calendar/v3/users/me/calendarList",sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);

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

    kind = CkJsonObjectW_stringOf(json,L"kind");
    etag = CkJsonObjectW_stringOf(json,L"etag");
    nextSyncToken = CkJsonObjectW_stringOf(json,L"nextSyncToken");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"items");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        kind = CkJsonObjectW_stringOf(json,L"items[i].kind");
        etag = CkJsonObjectW_stringOf(json,L"items[i].etag");
        id = CkJsonObjectW_stringOf(json,L"items[i].id");
        summary = CkJsonObjectW_stringOf(json,L"items[i].summary");
        timeZone = CkJsonObjectW_stringOf(json,L"items[i].timeZone");
        colorId = CkJsonObjectW_stringOf(json,L"items[i].colorId");
        backgroundColor = CkJsonObjectW_stringOf(json,L"items[i].backgroundColor");
        foregroundColor = CkJsonObjectW_stringOf(json,L"items[i].foregroundColor");
        selected = CkJsonObjectW_BoolOf(json,L"items[i].selected");
        accessRole = CkJsonObjectW_stringOf(json,L"items[i].accessRole");
        primary = CkJsonObjectW_BoolOf(json,L"items[i].primary");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(json,L"items[i].defaultReminders");
        while (j < count_j) {
            CkJsonObjectW_putJ(json,j);
            method = CkJsonObjectW_stringOf(json,L"items[i].defaultReminders[j].method");
            minutes = CkJsonObjectW_IntOf(json,L"items[i].defaultReminders[j].minutes");
            j = j + 1;
        }

        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(json,L"items[i].notificationSettings.notifications");
        while (j < count_j) {
            CkJsonObjectW_putJ(json,j);
            type = CkJsonObjectW_stringOf(json,L"items[i].notificationSettings.notifications[j].type");
            method = CkJsonObjectW_stringOf(json,L"items[i].notificationSettings.notifications[j].method");
            j = j + 1;
        }

        i = i + 1;
    }

    wprintf(L"Example Completed.\n");


    CkRestW_Dispose(rest);
    CkOAuth2W_Dispose(oauth2);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(json);

    }

Sample JSON Response Body

{
 "kind": "calendar#calendarList",
 "etag": "\"p33gdfl6bualde0g\"",
 "nextSyncToken": "CODX1MvyqtcCEhhzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20=",
 "items": [
  {
   "kind": "calendar#calendarListEntry",
   "etag": "\"1465249947472000\"",
   "id": "support@chilkatcloud.com",
   "summary": "support@chilkatcloud.com",
   "timeZone": "America/Chicago",
   "colorId": "14",
   "backgroundColor": "#9fe1e7",
   "foregroundColor": "#000000",
   "selected": true,
   "accessRole": "owner",
   "defaultReminders": [
    {
     "method": "popup",
     "minutes": 10
    }
   ],
   "notificationSettings": {
    "notifications": [
     {
      "type": "eventCreation",
      "method": "email"
     },
     {
      "type": "eventChange",
      "method": "email"
     },
     {
      "type": "eventCancellation",
      "method": "email"
     },
     {
      "type": "eventResponse",
      "method": "email"
     }
    ]
   },
   "primary": true
  },
  {
   "kind": "calendar#calendarListEntry",
   "etag": "\"1502373382732000\"",
   "id": "#contacts@group.v.calendar.google.com",
   "summary": "Contacts",
   "timeZone": "America/Chicago",
   "colorId": "13",
   "backgroundColor": "#92e1c0",
   "foregroundColor": "#000000",
   "selected": true,
   "accessRole": "reader",
   "defaultReminders": []
  },
  {
   "kind": "calendar#calendarListEntry",
   "etag": "\"1502373376447000\"",
   "id": "en.usa#holiday@group.v.calendar.google.com",
   "summary": "Holidays in United States",
   "timeZone": "America/Chicago",
   "colorId": "8",
   "backgroundColor": "#16a765",
   "foregroundColor": "#000000",
   "selected": true,
   "accessRole": "reader",
   "defaultReminders": []
  }
 ]
}