Unicode C++ Google Calendar: Update (Patch) a Calendar Entry

Back to Index

Updates an entry on the user's calendar list.
This example updates the "summary" for the calendar having the ID = "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com". The new summary will be "Party Calendar".

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


#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    CkRestW rest;
    bool success;

    //   Provide a previously obtained OAuth2 access token.
    CkOAuth2W oauth2;
    oauth2.put_AccessToken(L"OAUTH2_ACCESS_TOKEN");
    rest.SetAuthOAuth2(oauth2);

    success = rest.Connect(L"www.googleapis.com",443,true,true);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    CkJsonObjectW jsonReq;
    jsonReq.UpdateString(L"summary",L"Party Calendar");

    CkStringBuilderW sbReq;
    jsonReq.EmitSb(sbReq);

    rest.AddHeader(L"Content-Type",L"application/json");

    CkStringBuilderW sbJson;
    success = rest.FullRequestSb(L"PATCH",L"/calendar/v3/calendars/chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",sbReq,sbJson);
    if (success != true) {
        wprintf(L"%s\n",rest.lastErrorText());
        return;
    }

    if (rest.get_ResponseStatusCode() != 200) {
        wprintf(L"Received error response code: %d\n",rest.get_ResponseStatusCode());
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",sbJson.getAsString());
        return;
    }

    CkJsonObjectW json;
    json.LoadSb(sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.
    const wchar_t *kind = 0;
    const wchar_t *etag = 0;
    const wchar_t *id = 0;
    const wchar_t *summary = 0;
    const wchar_t *timeZone = 0;

    kind = json.stringOf(L"kind");
    etag = json.stringOf(L"etag");
    id = json.stringOf(L"id");
    summary = json.stringOf(L"summary");
    timeZone = json.stringOf(L"timeZone");

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

Sample JSON Request Body

{  
"summary": "Party Calendar" 
}



  

Sample JSON Response Body

{
  "kind": "calendar#calendar",
  "etag": "\"BKjXnZpXR6E5ueFWG3UJk-2POYg/jcCkAVFAjoCovUbrUQlnks64qfY\"",
  "id": "chilkatcloud.com_su2u8trmo6rlq2jh6cr9hb032o@group.calendar.google.com",
  "summary": "Party Calendar",
  "timeZone": "UTC"
}