Xbase++
Xbase++
Move a GMail Message to Trash
See more GMail REST API Examples
Moves a specific GMail email message to trash.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL cId
LOCAL cUserId
LOCAL cUrl
LOCAL oResp
nSuccess := 0
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("Chilkat.Http")
oHttp:AuthToken := "GMAIL-ACCESS-TOKEN"
// The id of the GMail message to move to Trash.
cId := "16678c485e7f0a0c"
cUserId := "me"
oHttp:SetUrlVar("userId", "me")
oHttp:SetUrlVar("id", cId)
// Move to trash by POSTing w/ an empty request body.
cUrl := "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}/trash"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpStr("POST", cUrl, "", "", "", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
? "status = " + Str(oResp:StatusCode)
// A 200 response status indicate success.
IF (oResp:StatusCode != 200)
? oResp:BodyStr
? "Failed."
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
// A successful repsonse contains JSON that looks like this:
// {
// "id": "16678c485e7f0a0c",
// "threadId": "16678c485e7f0a0c",
// "labelIds": [
// "TRASH",
// "CATEGORY_SOCIAL"
// ]
// }
? "response body:"
? oResp:BodyStr
? "Message moved to trash!"
oHttp:destroy()
oResp:destroy()