PowerBuilder 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


integer li_rc
oleobject loo_Rest
integer li_Success
oleobject loo_Oauth2
oleobject loo_SbJson
oleobject loo_Json
integer i
integer li_Count_i
string ls_Kind
string ls_Id
string ls_CreatedTime
string ls_ModifiedTime
string ls_AuthorKind
string ls_AuthorDisplayName
string ls_AuthorPhotoLink
integer li_AuthorMe
string ls_HtmlContent
string ls_Content
integer li_Deleted
integer li_Resolved
integer j
integer li_Count_j
string ls_Action

loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
    destroy loo_Rest
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//   Provide a previously obtained OAuth2 access token.
loo_Oauth2 = create oleobject
li_rc = loo_Oauth2.ConnectToNewObject("Chilkat_9_5_0.OAuth2")

loo_Oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loo_Rest.SetAuthOAuth2(loo_Oauth2)

li_Success = loo_Rest.Connect("www.googleapis.com",443,1,1)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    return
end if

loo_Rest.AddQueryParam("fields","comments")

loo_SbJson = create oleobject
li_rc = loo_SbJson.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")

li_Success = loo_Rest.FullRequestNoBodySb("GET","/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments",loo_SbJson)
if li_Success <> 1 then
    Write-Debug loo_Rest.LastErrorText
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

if loo_Rest.ResponseStatusCode <> 200 then
    Write-Debug "Received error response code: " + string(loo_Rest.ResponseStatusCode)
    Write-Debug "Response body:"
    Write-Debug loo_SbJson.GetAsString()
    destroy loo_Rest
    destroy loo_Oauth2
    destroy loo_SbJson
    return
end if

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat_9_5_0.JsonObject")

loo_Json.LoadSb(loo_SbJson)

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

i = 0
li_Count_i = loo_Json.SizeOfArray("comments")
do while i < li_Count_i
    loo_Json.I = i
    ls_Kind = loo_Json.StringOf("comments[i].kind")
    ls_Id = loo_Json.StringOf("comments[i].id")
    ls_CreatedTime = loo_Json.StringOf("comments[i].createdTime")
    ls_ModifiedTime = loo_Json.StringOf("comments[i].modifiedTime")
    ls_AuthorKind = loo_Json.StringOf("comments[i].author.kind")
    ls_AuthorDisplayName = loo_Json.StringOf("comments[i].author.displayName")
    ls_AuthorPhotoLink = loo_Json.StringOf("comments[i].author.photoLink")
    li_AuthorMe = loo_Json.BoolOf("comments[i].author.me")
    ls_HtmlContent = loo_Json.StringOf("comments[i].htmlContent")
    ls_Content = loo_Json.StringOf("comments[i].content")
    li_Deleted = loo_Json.BoolOf("comments[i].deleted")
    li_Resolved = loo_Json.BoolOf("comments[i].resolved")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("comments[i].replies")
    do while j < li_Count_j
        loo_Json.J = j
        ls_Kind = loo_Json.StringOf("comments[i].replies[j].kind")
        ls_Id = loo_Json.StringOf("comments[i].replies[j].id")
        ls_CreatedTime = loo_Json.StringOf("comments[i].replies[j].createdTime")
        ls_ModifiedTime = loo_Json.StringOf("comments[i].replies[j].modifiedTime")
        ls_AuthorKind = loo_Json.StringOf("comments[i].replies[j].author.kind")
        ls_AuthorDisplayName = loo_Json.StringOf("comments[i].replies[j].author.displayName")
        ls_AuthorPhotoLink = loo_Json.StringOf("comments[i].replies[j].author.photoLink")
        li_AuthorMe = loo_Json.BoolOf("comments[i].replies[j].author.me")
        ls_HtmlContent = loo_Json.StringOf("comments[i].replies[j].htmlContent")
        ls_Content = loo_Json.StringOf("comments[i].replies[j].content")
        li_Deleted = loo_Json.BoolOf("comments[i].replies[j].deleted")
        ls_Action = loo_Json.StringOf("comments[i].replies[j].action")
        j = j + 1
    loop
    i = i + 1
loop

Write-Debug "Example Completed."


destroy loo_Rest
destroy loo_Oauth2
destroy loo_SbJson
destroy loo_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"
        }
      ]
    }
  ]
}