Unicode C++ Google Drive: List Replies for a Specified Comment on a File

Back to Index

Lists the replies for a particular comment on a file. The file is specified by file ID. This example lists replies for comment (id="AAAABg7tSGw") on the file having id = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw".

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


#include <CkRestW.h>
#include <CkOAuth2W.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.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"replies");

    CkStringBuilderW sbJson;
    success = rest.FullRequestNoBodySb(L"GET",L"/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies",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.
    int i;
    int count_i;
    const wchar_t *kind = 0;
    const wchar_t *id = 0;
    const wchar_t *createdTime = 0;
    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 *htmlContent = 0;
    const wchar_t *content = 0;
    bool deleted;
    const wchar_t *action = 0;

    i = 0;
    count_i = json.SizeOfArray(L"replies");
    while (i < count_i) {
        json.put_I(i);
        kind = json.stringOf(L"replies[i].kind");
        id = json.stringOf(L"replies[i].id");
        createdTime = json.stringOf(L"replies[i].createdTime");
        modifiedTime = json.stringOf(L"replies[i].modifiedTime");
        authorKind = json.stringOf(L"replies[i].author.kind");
        authorDisplayName = json.stringOf(L"replies[i].author.displayName");
        authorPhotoLink = json.stringOf(L"replies[i].author.photoLink");
        authorMe = json.BoolOf(L"replies[i].author.me");
        htmlContent = json.stringOf(L"replies[i].htmlContent");
        content = json.stringOf(L"replies[i].content");
        deleted = json.BoolOf(L"replies[i].deleted");
        action = json.stringOf(L"replies[i].action");
        i = i + 1;
    }

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

Sample JSON Response Body

{
  "replies": [
    {
      "kind": "drive#reply",
      "id": "AAAABg76H9g",
      "createdTime": "2017-11-13T18:24:12.782Z",
      "modifiedTime": "2017-11-13T18:24:12.782Z",
      "author": {
        "kind": "drive#user",
        "displayName": "Matt Fausey",
        "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
        "me": true
      },
      "htmlContent": "This is the first reply to a comment.",
      "content": "This is the first reply to a comment.",
      "deleted": false,
      "action": "reopen"
    },
    {
      "kind": "drive#reply",
      "id": "AAAABg76H9k",
      "createdTime": "2017-11-13T18:24:45.085Z",
      "modifiedTime": "2017-11-13T18:24:45.085Z",
      "author": {
        "kind": "drive#user",
        "displayName": "Matt Fausey",
        "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
        "me": true
      },
      "htmlContent": "This is the second reply to a comment.",
      "content": "This is the second reply to a comment.",
      "deleted": false,
      "action": "resolve"
    },
    {
      "kind": "drive#reply",
      "id": "AAAABg76H9o",
      "createdTime": "2017-11-13T18:25:11.828Z",
      "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
      },
      "htmlContent": "This is the third reply to a comment.",
      "content": "This is the third reply to a comment.",
      "deleted": false,
      "action": "resolve"
    }
  ]
}