Unicode C++ Google Drive: Update a Comment

Back to Index

Updates (modifies) a particular comment on a file. This example updates the comment (id="AAAABg7tSGw") from the file having id = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw".

Documentation: https://developers.google.com/drive/v3/reference/comments/update


#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;
    }

    rest.AddQueryParam(L"fields",L"id,author,content");

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    CkJsonObjectW jsonReq;
    jsonReq.UpdateString(L"content",L"This is the updated comment.");

    CkStringBuilderW sbReq;
    jsonReq.EmitSb(sbReq);

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

    CkStringBuilderW sbJson;
    success = rest.FullRequestSb(L"PATCH",L"/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw",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 *id = 0;
    const wchar_t *authorKind = 0;
    const wchar_t *authorDisplayName = 0;
    const wchar_t *authorPhotoLink = 0;
    bool authorMe;
    const wchar_t *content = 0;

    id = json.stringOf(L"id");
    authorKind = json.stringOf(L"author.kind");
    authorDisplayName = json.stringOf(L"author.displayName");
    authorPhotoLink = json.stringOf(L"author.photoLink");
    authorMe = json.BoolOf(L"author.me");
    content = json.stringOf(L"content");

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

Sample JSON Request Body

{
  "content": "This is the updated comment."
}

Sample JSON Response Body

{
  "id": "AAAABg7tSGw",
  "author": {
    "kind": "drive#user",
    "displayName": "Matt Fausey",
    "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
    "me": true
  },
  "content": "This is the updated comment."
}