DataFlex 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


Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vOauth2
    Handle hoOauth2
    Variant vSbJson
    Handle hoSbJson
    Handle hoJson
    Integer i
    Integer iCount_i
    String sKind
    String sId
    String sCreatedTime
    String sModifiedTime
    String sAuthorKind
    String sAuthorDisplayName
    String sAuthorPhotoLink
    Boolean iAuthorMe
    String sHtmlContent
    String sContent
    Boolean iDeleted
    Boolean iResolved
    Integer j
    Integer iCount_j
    String sAction
    String sTemp1
    Integer iTemp1

    Get Create (RefClass(cComChilkatRest)) To hoRest
    If (Not(IsComObjectCreated(hoRest))) Begin
        Send CreateComObject of hoRest
    End

    //   Provide a previously obtained OAuth2 access token.
    Get Create (RefClass(cComChilkatOAuth2)) To hoOauth2
    If (Not(IsComObjectCreated(hoOauth2))) Begin
        Send CreateComObject of hoOauth2
    End
    Set ComAccessToken Of hoOauth2 To "OAUTH2_ACCESS_TOKEN"
    Get pvComObject of hoOauth2 to vOauth2
    Get ComSetAuthOAuth2 Of hoRest vOauth2 To iSuccess

    Get ComConnect Of hoRest "www.googleapis.com" 443 True True To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComAddQueryParam Of hoRest "fields" "comments" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
    If (Not(IsComObjectCreated(hoSbJson))) Begin
        Send CreateComObject of hoSbJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComFullRequestNoBodySb Of hoRest "GET" "/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments" vSbJson To iSuccess
    If (iSuccess <> True) Begin
        Get ComLastErrorText Of hoRest To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComResponseStatusCode Of hoRest To iTemp1
    If (iTemp1 <> 200) Begin
        Get ComResponseStatusCode Of hoRest To iTemp1
        Showln "Received error response code: " iTemp1
        Showln "Response body:"
        Get ComGetAsString Of hoSbJson To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get Create (RefClass(cComChilkatJsonObject)) To hoJson
    If (Not(IsComObjectCreated(hoJson))) Begin
        Send CreateComObject of hoJson
    End
    Get pvComObject of hoSbJson to vSbJson
    Get ComLoadSb Of hoJson vSbJson To iSuccess

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

    Move 0 To i
    Get ComSizeOfArray Of hoJson "comments" To iCount_i
    While (i < iCount_i)
        Set ComI Of hoJson To i
        Get ComStringOf Of hoJson "comments[i].kind" To sKind
        Get ComStringOf Of hoJson "comments[i].id" To sId
        Get ComStringOf Of hoJson "comments[i].createdTime" To sCreatedTime
        Get ComStringOf Of hoJson "comments[i].modifiedTime" To sModifiedTime
        Get ComStringOf Of hoJson "comments[i].author.kind" To sAuthorKind
        Get ComStringOf Of hoJson "comments[i].author.displayName" To sAuthorDisplayName
        Get ComStringOf Of hoJson "comments[i].author.photoLink" To sAuthorPhotoLink
        Get ComBoolOf Of hoJson "comments[i].author.me" To iAuthorMe
        Get ComStringOf Of hoJson "comments[i].htmlContent" To sHtmlContent
        Get ComStringOf Of hoJson "comments[i].content" To sContent
        Get ComBoolOf Of hoJson "comments[i].deleted" To iDeleted
        Get ComBoolOf Of hoJson "comments[i].resolved" To iResolved
        Move 0 To j
        Get ComSizeOfArray Of hoJson "comments[i].replies" To iCount_j
        While (j < iCount_j)
            Set ComJ Of hoJson To j
            Get ComStringOf Of hoJson "comments[i].replies[j].kind" To sKind
            Get ComStringOf Of hoJson "comments[i].replies[j].id" To sId
            Get ComStringOf Of hoJson "comments[i].replies[j].createdTime" To sCreatedTime
            Get ComStringOf Of hoJson "comments[i].replies[j].modifiedTime" To sModifiedTime
            Get ComStringOf Of hoJson "comments[i].replies[j].author.kind" To sAuthorKind
            Get ComStringOf Of hoJson "comments[i].replies[j].author.displayName" To sAuthorDisplayName
            Get ComStringOf Of hoJson "comments[i].replies[j].author.photoLink" To sAuthorPhotoLink
            Get ComBoolOf Of hoJson "comments[i].replies[j].author.me" To iAuthorMe
            Get ComStringOf Of hoJson "comments[i].replies[j].htmlContent" To sHtmlContent
            Get ComStringOf Of hoJson "comments[i].replies[j].content" To sContent
            Get ComBoolOf Of hoJson "comments[i].replies[j].deleted" To iDeleted
            Get ComStringOf Of hoJson "comments[i].replies[j].action" To sAction
            Move j + 1 To j
        Loop

        Move i + 1 To i
    Loop

    Showln "Example Completed."


End_Procedure

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