Unicode C Google Drive: List Comments on a File

Back to Index

Lists the comment on a file. The file is specified by file ID. This example lists comments on the file having id = "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw".

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


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

void ChilkatSample(void)
    {
    HCkRestW rest;
    BOOL success;
    HCkOAuth2W oauth2;
    HCkStringBuilderW sbJson;
    HCkJsonObjectW json;
    int i;
    int count_i;
    const wchar_t *kind;
    const wchar_t *id;
    const wchar_t *createdTime;
    const wchar_t *modifiedTime;
    const wchar_t *authorKind;
    const wchar_t *authorDisplayName;
    const wchar_t *authorPhotoLink;
    BOOL authorMe;
    const wchar_t *htmlContent;
    const wchar_t *content;
    BOOL deleted;
    BOOL resolved;
    int j;
    int count_j;
    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"comments");

    sbJson = CkStringBuilderW_Create();
    success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments",sbJson);
    if (success != TRUE) {
        wprintf(L"%s\n",CkRestW_lastErrorText(rest));
        CkRestW_Dispose(rest);
        CkOAuth2W_Dispose(oauth2);
        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);
        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.

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(json,L"comments");
    while (i < count_i) {
        CkJsonObjectW_putI(json,i);
        kind = CkJsonObjectW_stringOf(json,L"comments[i].kind");
        id = CkJsonObjectW_stringOf(json,L"comments[i].id");
        createdTime = CkJsonObjectW_stringOf(json,L"comments[i].createdTime");
        modifiedTime = CkJsonObjectW_stringOf(json,L"comments[i].modifiedTime");
        authorKind = CkJsonObjectW_stringOf(json,L"comments[i].author.kind");
        authorDisplayName = CkJsonObjectW_stringOf(json,L"comments[i].author.displayName");
        authorPhotoLink = CkJsonObjectW_stringOf(json,L"comments[i].author.photoLink");
        authorMe = CkJsonObjectW_BoolOf(json,L"comments[i].author.me");
        htmlContent = CkJsonObjectW_stringOf(json,L"comments[i].htmlContent");
        content = CkJsonObjectW_stringOf(json,L"comments[i].content");
        deleted = CkJsonObjectW_BoolOf(json,L"comments[i].deleted");
        resolved = CkJsonObjectW_BoolOf(json,L"comments[i].resolved");
        j = 0;
        count_j = CkJsonObjectW_SizeOfArray(json,L"comments[i].replies");
        while (j < count_j) {
            CkJsonObjectW_putJ(json,j);
            kind = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].kind");
            id = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].id");
            createdTime = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].createdTime");
            modifiedTime = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].modifiedTime");
            authorKind = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].author.kind");
            authorDisplayName = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].author.displayName");
            authorPhotoLink = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].author.photoLink");
            authorMe = CkJsonObjectW_BoolOf(json,L"comments[i].replies[j].author.me");
            htmlContent = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].htmlContent");
            content = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].content");
            deleted = CkJsonObjectW_BoolOf(json,L"comments[i].replies[j].deleted");
            action = CkJsonObjectW_stringOf(json,L"comments[i].replies[j].action");
            j = j + 1;
        }

        i = i + 1;
    }

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


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

    }

Sample JSON Response Body

{
  "comments": [
    {
      "kind": "drive#comment",
      "id": "AAAABg7vWfw",
      "createdTime": "2017-11-13T17:51:57.906Z",
      "modifiedTime": "2017-11-13T17:51:57.906Z",
      "author": {
        "kind": "drive#user",
        "displayName": "Matt Fausey",
        "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
        "me": true
      },
      "htmlContent": "This is the 2nd test comment about this file...",
      "content": "This is the 2nd test comment about this file...",
      "deleted": false,
      "resolved": false,
      "replies": [
      ]
    },
    {
      "kind": "drive#comment",
      "id": "AAAABg7tSGw",
      "createdTime": "2017-11-13T17:43:05.735Z",
      "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 a test comment about this file...",
      "content": "This is a test comment about this file...",
      "deleted": false,
      "resolved": true,
      "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"
        }
      ]
    }
  ]
}