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

void ChilkatSample(void)
    {
    HCkRest rest;
    BOOL success;
    HCkOAuth2 oauth2;
    HCkStringBuilder sbJson;
    HCkJsonObject json;
    int i;
    int count_i;
    const char *kind;
    const char *id;
    const char *createdTime;
    const char *modifiedTime;
    const char *authorKind;
    const char *authorDisplayName;
    const char *authorPhotoLink;
    BOOL authorMe;
    const char *htmlContent;
    const char *content;
    BOOL deleted;
    const char *action;

    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","replies");

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

    i = 0;
    count_i = CkJsonObject_SizeOfArray(json,"replies");
    while (i < count_i) {
        CkJsonObject_putI(json,i);
        kind = CkJsonObject_stringOf(json,"replies[i].kind");
        id = CkJsonObject_stringOf(json,"replies[i].id");
        createdTime = CkJsonObject_stringOf(json,"replies[i].createdTime");
        modifiedTime = CkJsonObject_stringOf(json,"replies[i].modifiedTime");
        authorKind = CkJsonObject_stringOf(json,"replies[i].author.kind");
        authorDisplayName = CkJsonObject_stringOf(json,"replies[i].author.displayName");
        authorPhotoLink = CkJsonObject_stringOf(json,"replies[i].author.photoLink");
        authorMe = CkJsonObject_BoolOf(json,"replies[i].author.me");
        htmlContent = CkJsonObject_stringOf(json,"replies[i].htmlContent");
        content = CkJsonObject_stringOf(json,"replies[i].content");
        deleted = CkJsonObject_BoolOf(json,"replies[i].deleted");
        action = CkJsonObject_stringOf(json,"replies[i].action");
        i = i + 1;
    }

    printf("Example Completed.\n");


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

    }

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