Xbase++
Xbase++
Get a List of Message IDs in GMail User's Mailbox
See more GMail REST API Examples
Demonstrates how to get a list of message IDs in a GMail mailbox. The "userId" can be either the user's email address or the special value "me" to indicate the authenticated user.Chilkat Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oResp
LOCAL oJsonResponse
LOCAL cId
LOCAL cThreadId
LOCAL nResultSizeEstimate
LOCAL i
LOCAL nCount_i
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 := "ACCESS_TOKEN"
oHttp:Accept := "application/json"
oResp := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpNoBody("GET", "https://www.googleapis.com/gmail/v1/users/userId/messages", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oResp:destroy()
RETURN
ENDIF
? "Response Status Code: " + Str(oResp:StatusCode)
oJsonResponse := CreateObject("Chilkat.JsonObject")
oJsonResponse:Load(oResp:BodyStr)
oJsonResponse:EmitCompact := 0
? oJsonResponse:Emit()
IF (oResp:StatusCode != 200)
? "Failed."
oHttp:destroy()
oResp:destroy()
oJsonResponse:destroy()
RETURN
ENDIF
// {
// "messages": [
// users.messages Resource
// ],
// "nextPageToken": string,
// "resultSizeEstimate": unsigned integer
// }
nResultSizeEstimate := oJsonResponse:IntOf("resultSizeEstimate")
i := 0
nCount_i := oJsonResponse:SizeOfArray("messages")
DO WHILE i < nCount_i
oJsonResponse:I := i
cId := oJsonResponse:StringOf("messages[i].id")
cThreadId := oJsonResponse:StringOf("messages[i].threadId")
i := i + 1
ENDDO
oHttp:destroy()
oResp:destroy()
oJsonResponse:destroy()