DataFlex Google Drive: Update (Modify) a Reply on a Comment

Back to Index

Modifies a reply on a comment. This example modifies reply (id="AAAABg76H9g") on comment (id="AAAABg7tSGw") on the file (id= "0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw")

Documentation: https://developers.google.com/drive/v3/reference/replies/update


Use ChilkatAx-9.5.0-win32.pkg

Procedure Test
    Handle hoRest
    Boolean iSuccess
    Variant vOauth2
    Handle hoOauth2
Req    Handle hoJsonReq
    Variant vSbReq
    Handle hoSbReq
    Variant vSbJson
    Handle hoSbJson
    Handle hoJson
    String sModifiedTime
    String sAuthorKind
    String sAuthorDisplayName
    String sAuthorPhotoLink
    Boolean iAuthorMe
    String sContent
    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" "modifiedTime,author,content,action" To iSuccess

    //  The following code creates the JSON request body.
    //  The JSON created by this code is shown below.
    Get Create (RefClass(cComChilkatJsonObject)) To hoJsonReq
    If (Not(IsComObjectCreated(hoJsonReq))) Begin
        Send CreateComObject of hoJsonReq
    End
    Get ComUpdateString Of hoJsonReq "content" "This is the 1st reply to this comment..." To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbReq
    If (Not(IsComObjectCreated(hoSbReq))) Begin
        Send CreateComObject of hoSbReq
    End
    Get pvComObject of hoSbReq to vSbReq
    Get ComEmitSb Of hoJsonReq vSbReq To iSuccess

    Get ComAddHeader Of hoRest "Content-Type" "application/json" To iSuccess

    Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
    If (Not(IsComObjectCreated(hoSbJson))) Begin
        Send CreateComObject of hoSbJson
    End
    Get pvComObject of hoSbReq to vSbReq
    Get pvComObject of hoSbJson to vSbJson
    Get ComFullRequestSb Of hoRest "PATCH" "/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies/AAAABg76H9g" vSbReq 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.

    Get ComStringOf Of hoJson "modifiedTime" To sModifiedTime
    Get ComStringOf Of hoJson "author.kind" To sAuthorKind
    Get ComStringOf Of hoJson "author.displayName" To sAuthorDisplayName
    Get ComStringOf Of hoJson "author.photoLink" To sAuthorPhotoLink
    Get ComBoolOf Of hoJson "author.me" To iAuthorMe
    Get ComStringOf Of hoJson "content" To sContent

    Showln "Example Completed."


End_Procedure

Sample JSON Request Body

{
    "content": "This is the 1st reply to this comment..."
}

Sample JSON Response Body

{
  "modifiedTime": "2017-11-13T19:37:13.089Z",
  "author": {
    "kind": "drive#user",
    "displayName": "Matt Fausey",
    "photoLink": "//ssl.gstatic.com/s2/profiles/images/silhouette96.png",
    "me": true
  },
  "content": "This is the 1st reply to this comment..."
}