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 <C_CkRest.h>
#include <C_CkOAuth2.h>
#include <C_CkJsonObject.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkOAuth2 oauth2;
    HCkJsonObject jsonReq;
    HCkStringBuilder sbReq;
    HCkStringBuilder sbJson;
    HCkJsonObject json;
    const char *modifiedTime;
    const char *authorKind;
    const char *authorDisplayName;
    const char *authorPhotoLink;
    BOOL authorMe;
    const char *content;

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

    CkRest_AddQueryParam(rest,"fields","modifiedTime,author,content,action");

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    jsonReq = CkJsonObject_Create();
    CkJsonObject_UpdateString(jsonReq,"content","This is the 1st reply to this comment...");

    sbReq = CkStringBuilder_Create();
    CkJsonObject_EmitSb(jsonReq,sbReq);

    CkRest_AddHeader(rest,"Content-Type","application/json");

    sbJson = CkStringBuilder_Create();
    success = CkRest_FullRequestSb(rest,"PATCH","/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies/AAAABg76H9g",sbReq,sbJson);
    if (success != TRUE) {
        printf("%s\n",CkRest_lastErrorText(rest));
        CkRest_Dispose(rest);
        CkOAuth2_Dispose(oauth2);
        CkJsonObject_Dispose(jsonReq);
        CkStringBuilder_Dispose(sbReq);
        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);
        CkJsonObject_Dispose(jsonReq);
        CkStringBuilder_Dispose(sbReq);
        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.

    modifiedTime = CkJsonObject_stringOf(json,"modifiedTime");
    authorKind = CkJsonObject_stringOf(json,"author.kind");
    authorDisplayName = CkJsonObject_stringOf(json,"author.displayName");
    authorPhotoLink = CkJsonObject_stringOf(json,"author.photoLink");
    authorMe = CkJsonObject_BoolOf(json,"author.me");
    content = CkJsonObject_stringOf(json,"content");

    printf("Example Completed.\n");


    CkRest_Dispose(rest);
    CkOAuth2_Dispose(oauth2);
    CkJsonObject_Dispose(jsonReq);
    CkStringBuilder_Dispose(sbReq);
    CkStringBuilder_Dispose(sbJson);
    CkJsonObject_Dispose(json);

    }

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..."
}