Unicode C Google Drive: Creates a New Reply to a Comment

Back to Index

Creates a new reply to a comment. This example creates a reply to a comment on the file having fileId = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw", and commentId = "AAAABg7tSGw".

Documentation: https://developers.google.com/drive/v3/reference/replies/create


#include <C_CkRestW.h>
#include <C_CkOAuth2W.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkOAuth2W oauth2;
    HCkJsonObjectW jsonReq;
    HCkStringBuilderW sbReq;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    const wchar_t *modifiedTime;
    const wchar_t *authorKind;
    const wchar_t *authorDisplayName;
    const wchar_t *authorPhotoLink;
    BOOL authorMe;
    const wchar_t *content;
    const wchar_t *action;

    rest = CkRestW_Create();

    //   Provide a previously obtained OAuth2 access token.
    oauth2 = CkOAuth2W_Create();
    CkOAuth2W_putAccessToken(oauth2,L"OAUTH2_ACCESS_TOKEN");
    CkRestW_SetAuthOAuth2(rest,oauth2);

    success = CkRestW_Connect(rest,L"www.googleapis.com",443,TRUE,TRUE);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        return;
    }

    CkRestW_AddQueryParam(rest,L"fields",L"modifiedTime,author,content,action");

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    jsonReq = CkJsonObjectW_Create();
    CkJsonObjectW_UpdateString(jsonReq,L"content",L"This is the second reply to a comment.");
    CkJsonObjectW_UpdateString(jsonReq,L"action",L"resolve");

    sbReq = CkStringBuilderW_Create();
    CkJsonObjectW_EmitSb(jsonReq,sbReq);

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

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestSb(rest,L"POST",L"/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies",sbReq,sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    if (CkRestW_getResponseStatusCode(rest) != 200) {
        wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest));
        wprintf(L"Response body:\n");
        wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        CkJsonObjectW_Dispose(jsonReq);
        CkStringBuilderW_Dispose(sbReq);
        CkStringBuilderW_Dispose(sbJson);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.

    modifiedTime = CkJsonObjectW_stringOf(json,L"modifiedTime");
    authorKind = CkJsonObjectW_stringOf(json,L"author.kind");
    authorDisplayName = CkJsonObjectW_stringOf(json,L"author.displayName");
    authorPhotoLink = CkJsonObjectW_stringOf(json,L"author.photoLink");
    authorMe = CkJsonObjectW_BoolOf(json,L"author.me");
    content = CkJsonObjectW_stringOf(json,L"content");
    action = CkJsonObjectW_stringOf(json,L"action");

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


    CkRestW_Dispose(rest);
    CkOAuth2W_Dispose(oauth2);
    CkJsonObjectW_Dispose(jsonReq);
    CkStringBuilderW_Dispose(sbReq);
    CkStringBuilderW_Dispose(sbJson);
    CkJsonObjectW_Dispose(json);

    }

Sample JSON Request Body

{
  "content": "This is the second reply to a comment.",
"action": "resolve"
}

Sample JSON Response Body

{
  "modifiedTime": "2017-11-13T18:25:11.828Z",
  "author": {
    "kind": "drive#user",
    "displayName": "Matt Fausey",
    "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
    "me": true
  },
  "content": "This is the second reply to a comment.",
  "action": "resolve"
}