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_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 *id;
    const char *summary;
    const char *timeZone;
    const char *colorId;
    const char *backgroundColor;
    const char *foregroundColor;
    BOOL selected;
    const char *accessRole;
    BOOL primary;
    int i;
    int count_i;
    const char *method;
    int minutes;
    const char *type;

    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/users/me/calendarList/support@chilkatcloud.com",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");
    id = CkJsonObject_stringOf(json,"id");
    summary = CkJsonObject_stringOf(json,"summary");
    timeZone = CkJsonObject_stringOf(json,"timeZone");
    colorId = CkJsonObject_stringOf(json,"colorId");
    backgroundColor = CkJsonObject_stringOf(json,"backgroundColor");
    foregroundColor = CkJsonObject_stringOf(json,"foregroundColor");
    selected = CkJsonObject_BoolOf(json,"selected");
    accessRole = CkJsonObject_stringOf(json,"accessRole");
    primary = CkJsonObject_BoolOf(json,"primary");
    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,"notificationSettings.notifications");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        type = CkJsonObject_stringOf(json,"notificationSettings.notifications[i].type");
        method = CkJsonObject_stringOf(json,"notificationSettings.notifications[i].method");
        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#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
}