Unicode C Google Calendar: Get Calendar

Back to Index

Returns an entry on the user's calendar list.
This example gets the calendar having the ID = "support@chilkatcloud.com".

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


#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 *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 i;
    int count_i;
    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/support@chilkatcloud.com",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");
    id = CkJsonObjectW_stringOf(json,L"id");
    summary = CkJsonObjectW_stringOf(json,L"summary");
    timeZone = CkJsonObjectW_stringOf(json,L"timeZone");
    colorId = CkJsonObjectW_stringOf(json,L"colorId");
    backgroundColor = CkJsonObjectW_stringOf(json,L"backgroundColor");
    foregroundColor = CkJsonObjectW_stringOf(json,L"foregroundColor");
    selected = CkJsonObjectW_BoolOf(json,L"selected");
    accessRole = CkJsonObjectW_stringOf(json,L"accessRole");
    primary = CkJsonObjectW_BoolOf(json,L"primary");
    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"defaultReminders");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        method = CkJsonObjectW_stringOf(json,L"defaultReminders[i].method");
        minutes = CkJsonObjectW_IntOf(json,L"defaultReminders[i].minutes");
        i = i + 1;
    }

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"notificationSettings.notifications");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        type = CkJsonObjectW_stringOf(json,L"notificationSettings.notifications[i].type");
        method = CkJsonObjectW_stringOf(json,L"notificationSettings.notifications[i].method");
        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#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
}