DataFlex
DataFlex
Move a GMail Message to Trash
See more GMail REST API Examples
Moves a specific GMail email message to trash.Chilkat DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
String sId
String sUserId
String sUrl
Variant vResp
Handle hoResp
String sTemp1
Integer iTemp1
Move False To iSuccess
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
Set ComAuthToken Of hoHttp To "GMAIL-ACCESS-TOKEN"
// The id of the GMail message to move to Trash.
Move "16678c485e7f0a0c" To sId
Move "me" To sUserId
Get ComSetUrlVar Of hoHttp "userId" "me" To iSuccess
Get ComSetUrlVar Of hoHttp "id" sId To iSuccess
// Move to trash by POSTing w/ an empty request body.
Move "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}/trash" To sUrl
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoResp to vResp
Get ComHttpStr Of hoHttp "POST" sUrl "" "" "" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComStatusCode Of hoResp To iTemp1
Showln "status = " iTemp1
// A 200 response status indicate success.
Get ComStatusCode Of hoResp To iTemp1
If (iTemp1 <> 200) Begin
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_Return
End
// A successful repsonse contains JSON that looks like this:
// {
// "id": "16678c485e7f0a0c",
// "threadId": "16678c485e7f0a0c",
// "labelIds": [
// "TRASH",
// "CATEGORY_SOCIAL"
// ]
// }
Showln "response body:"
Get ComBodyStr Of hoResp To sTemp1
Showln sTemp1
Showln "Message moved to trash!"
End_Procedure