Returns entries on the user's calendar 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 *nextSyncToken;
int i;
int count_i;
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 j;
int count_j;
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",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");
nextSyncToken = CkJsonObject_stringOf(json,"nextSyncToken");
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");
summary = CkJsonObject_stringOf(json,"items[i].summary");
timeZone = CkJsonObject_stringOf(json,"items[i].timeZone");
colorId = CkJsonObject_stringOf(json,"items[i].colorId");
backgroundColor = CkJsonObject_stringOf(json,"items[i].backgroundColor");
foregroundColor = CkJsonObject_stringOf(json,"items[i].foregroundColor");
selected = CkJsonObject_BoolOf(json,"items[i].selected");
accessRole = CkJsonObject_stringOf(json,"items[i].accessRole");
primary = CkJsonObject_BoolOf(json,"items[i].primary");
j = 0;
count_j = CkJsonObject_SizeOfArray(json,"items[i].defaultReminders");
while (j < count_j) {
CkJsonObject_putJ(json,j);
method = CkJsonObject_stringOf(json,"items[i].defaultReminders[j].method");
minutes = CkJsonObject_IntOf(json,"items[i].defaultReminders[j].minutes");
j = j + 1;
}
j = 0;
count_j = CkJsonObject_SizeOfArray(json,"items[i].notificationSettings.notifications");
while (j < count_j) {
CkJsonObject_putJ(json,j);
type = CkJsonObject_stringOf(json,"items[i].notificationSettings.notifications[j].type");
method = CkJsonObject_stringOf(json,"items[i].notificationSettings.notifications[j].method");
j = j + 1;
}
i = i + 1;
}
printf("Example Completed.\n");
CkRest_Dispose(rest);
CkOAuth2_Dispose(oauth2);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(json);
}
{
"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": []
}
]
}