Unicode C++ Google Drive: Update (Modify) a Reply on a Comment

Back to Index

Modifies a reply on a comment. This example modifies reply (id="AAAABg76H9g") on comment (id="AAAABg7tSGw") on the file (id= "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw")

Documentation: https://developers.google.com/drive/v3/reference/replies/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"modifiedTime,author,content,action");

    //  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 1st reply to this 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/replies/AAAABg76H9g",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 *modifiedTime = 0;
    const wchar_t *authorKind = 0;
    const wchar_t *authorDisplayName = 0;
    const wchar_t *authorPhotoLink = 0;
    bool authorMe;
    const wchar_t *content = 0;

    modifiedTime = json.stringOf(L"modifiedTime");
    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 1st reply to this comment..."
}

Sample JSON Response Body

{
  "modifiedTime": "2017-11-13T19:37:13.089Z",
  "author": {
    "kind": "drive#user",
    "displayName": "Matt Fausey",
    "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
    "me": true
  },
  "content": "This is the 1st reply to this comment..."
}