calendar.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#include <CkRest.h> #include <CkOAuth2.h> #include <CkStringBuilder.h> #include <CkJsonObject.h> void ChilkatSample(void) { CkRest rest; bool success; // Provide a previously obtained OAuth2 access token. CkOAuth2 oauth2; oauth2.put_AccessToken("OAUTH2_ACCESS_TOKEN"); rest.SetAuthOAuth2(oauth2); success = rest.Connect("www.googleapis.com",443,true,true); if (success != true) { std::cout << rest.lastErrorText() << "\r\n"; return; } CkStringBuilder sbJson; success = rest.FullRequestNoBodySb("GET","/calendar/v3/calendars/support@chilkatcloud.com/events",sbJson); if (success != true) { std::cout << rest.lastErrorText() << "\r\n"; return; } if (rest.get_ResponseStatusCode() != 200) { std::cout << "Received error response code: " << rest.get_ResponseStatusCode() << "\r\n"; std::cout << "Response body:" << "\r\n"; std::cout << sbJson.getAsString() << "\r\n"; return; } CkJsonObject json; json.LoadSb(sbJson); // The following code parses the JSON response. // A sample JSON response is shown below the sample code. const char *kind = 0; const char *etag = 0; const char *summary = 0; const char *updated = 0; const char *timeZone = 0; const char *accessRole = 0; const char *nextSyncToken = 0; int i; int count_i; const char *method = 0; int minutes; const char *id = 0; const char *status = 0; const char *htmlLink = 0; const char *created = 0; const char *creatorEmail = 0; bool creatorSelf; const char *organizerEmail = 0; bool organizerSelf; const char *startDateTime = 0; const char *endDateTime = 0; const char *iCalUID = 0; int sequence; const char *hangoutLink = 0; bool remindersUseDefault; const char *location = 0; kind = json.stringOf("kind"); etag = json.stringOf("etag"); summary = json.stringOf("summary"); updated = json.stringOf("updated"); timeZone = json.stringOf("timeZone"); accessRole = json.stringOf("accessRole"); nextSyncToken = json.stringOf("nextSyncToken"); i = 0; count_i = json.SizeOfArray("defaultReminders"); while (i < count_i) { json.put_I(i); method = json.stringOf("defaultReminders[i].method"); minutes = json.IntOf("defaultReminders[i].minutes"); i = i + 1; } i = 0; count_i = json.SizeOfArray("items"); while (i < count_i) { json.put_I(i); kind = json.stringOf("items[i].kind"); etag = json.stringOf("items[i].etag"); id = json.stringOf("items[i].id"); status = json.stringOf("items[i].status"); htmlLink = json.stringOf("items[i].htmlLink"); created = json.stringOf("items[i].created"); updated = json.stringOf("items[i].updated"); summary = json.stringOf("items[i].summary"); creatorEmail = json.stringOf("items[i].creator.email"); creatorSelf = json.BoolOf("items[i].creator.self"); organizerEmail = json.stringOf("items[i].organizer.email"); organizerSelf = json.BoolOf("items[i].organizer.self"); startDateTime = json.stringOf("items[i].start.dateTime"); endDateTime = json.stringOf("items[i].end.dateTime"); iCalUID = json.stringOf("items[i].iCalUID"); sequence = json.IntOf("items[i].sequence"); hangoutLink = json.stringOf("items[i].hangoutLink"); remindersUseDefault = json.BoolOf("items[i].reminders.useDefault"); location = json.stringOf("items[i].location"); i = i + 1; } std::cout << "Example Completed." << "\r\n"; } |