Tcl 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



load ./chilkat.dll

set rest [new_CkRest]

#   Provide a previously obtained OAuth2 access token.
set oauth2 [new_CkOAuth2]

CkOAuth2_put_AccessToken $oauth2 "OAUTH2_ACCESS_TOKEN"
CkRest_SetAuthOAuth2 $rest $oauth2

set success [CkRest_Connect $rest "www.googleapis.com" 443 1 1]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    exit
}

CkRest_AddQueryParam $rest "fields" "comments"

set sbJson [new_CkStringBuilder]

set success [CkRest_FullRequestNoBodySb $rest "GET" "/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments" $sbJson]
if {[expr $success != 1]} then {
    puts [CkRest_lastErrorText $rest]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    delete_CkStringBuilder $sbJson
    exit
}

if {[expr [CkRest_ResponseStatusCode $rest] != 200]} then {
    puts "Received error response code: [CkRest_ResponseStatusCode $rest]"
    puts "Response body:"
    puts [CkStringBuilder_getAsString $sbJson]
    delete_CkRest $rest
    delete_CkOAuth2 $oauth2
    delete_CkStringBuilder $sbJson
    exit
}

set json [new_CkJsonObject]

CkJsonObject_LoadSb $json $sbJson

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

set i 0
set count_i [CkJsonObject_SizeOfArray $json "comments"]
while {[expr $i < $count_i]} {
    CkJsonObject_put_I $json $i
    set kind [CkJsonObject_stringOf $json "comments[i].kind"]
    set id [CkJsonObject_stringOf $json "comments[i].id"]
    set createdTime [CkJsonObject_stringOf $json "comments[i].createdTime"]
    set modifiedTime [CkJsonObject_stringOf $json "comments[i].modifiedTime"]
    set authorKind [CkJsonObject_stringOf $json "comments[i].author.kind"]
    set authorDisplayName [CkJsonObject_stringOf $json "comments[i].author.displayName"]
    set authorPhotoLink [CkJsonObject_stringOf $json "comments[i].author.photoLink"]
    set authorMe [CkJsonObject_BoolOf $json "comments[i].author.me"]
    set htmlContent [CkJsonObject_stringOf $json "comments[i].htmlContent"]
    set content [CkJsonObject_stringOf $json "comments[i].content"]
    set deleted [CkJsonObject_BoolOf $json "comments[i].deleted"]
    set resolved [CkJsonObject_BoolOf $json "comments[i].resolved"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $json "comments[i].replies"]
    while {[expr $j < $count_j]} {
        CkJsonObject_put_J $json $j
        set kind [CkJsonObject_stringOf $json "comments[i].replies[j].kind"]
        set id [CkJsonObject_stringOf $json "comments[i].replies[j].id"]
        set createdTime [CkJsonObject_stringOf $json "comments[i].replies[j].createdTime"]
        set modifiedTime [CkJsonObject_stringOf $json "comments[i].replies[j].modifiedTime"]
        set authorKind [CkJsonObject_stringOf $json "comments[i].replies[j].author.kind"]
        set authorDisplayName [CkJsonObject_stringOf $json "comments[i].replies[j].author.displayName"]
        set authorPhotoLink [CkJsonObject_stringOf $json "comments[i].replies[j].author.photoLink"]
        set authorMe [CkJsonObject_BoolOf $json "comments[i].replies[j].author.me"]
        set htmlContent [CkJsonObject_stringOf $json "comments[i].replies[j].htmlContent"]
        set content [CkJsonObject_stringOf $json "comments[i].replies[j].content"]
        set deleted [CkJsonObject_BoolOf $json "comments[i].replies[j].deleted"]
        set action [CkJsonObject_stringOf $json "comments[i].replies[j].action"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}

puts "Example Completed."

delete_CkRest $rest
delete_CkOAuth2 $oauth2
delete_CkStringBuilder $sbJson
delete_CkJsonObject $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"
        }
      ]
    }
  ]
}