Visual FoxPro 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


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loJsonReq
LOCAL loSbReq
LOCAL loSbJson
LOCAL loJson
LOCAL lcModifiedTime
LOCAL lcAuthorKind
LOCAL lcAuthorDisplayName
LOCAL lcAuthorPhotoLink
LOCAL lnAuthorMe
LOCAL lcContent

loRest = CreateObject('Chilkat_9_5_0.Rest')

*   Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)

lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    CANCEL
ENDIF

loRest.AddQueryParam("fields","modifiedTime,author,content,action")

*  The following code creates the JSON request body.
*  The JSON created by this code is shown below.
loJsonReq = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonReq.UpdateString("content","This is the 1st reply to this comment...")

loSbReq = CreateObject('Chilkat_9_5_0.StringBuilder')
loJsonReq.EmitSb(loSbReq)

loRest.AddHeader("Content-Type","application/json")

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("PATCH","/drive/v3/files/0B5drHSd5ZHwgc3RhcnRlcl9maWxlX2Rhc2hlclYw/comments/AAAABg7tSGw/replies/AAAABg76H9g",loSbReq,loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loJsonReq
    RELEASE loSbReq
    RELEASE loSbJson
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loJsonReq
    RELEASE loSbReq
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.LoadSb(loSbJson)

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

lcModifiedTime = loJson.StringOf("modifiedTime")
lcAuthorKind = loJson.StringOf("author.kind")
lcAuthorDisplayName = loJson.StringOf("author.displayName")
lcAuthorPhotoLink = loJson.StringOf("author.photoLink")
lnAuthorMe = loJson.BoolOf("author.me")
lcContent = loJson.StringOf("content")

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loJsonReq
RELEASE loSbReq
RELEASE loSbJson
RELEASE loJson

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