Sample code for 30+ languages & platforms
Visual FoxPro

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

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loResp
LOCAL loJsonResponse
LOCAL lcId
LOCAL lcThreadId
LOCAL lnResultSizeEstimate
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

* This example requires the Chilkat API to have been previously unlocked.
* See Global Unlock Sample for sample code.

loHttp = CreateObject('Chilkat.Http')

loHttp.AuthToken = "ACCESS_TOKEN"

loHttp.Accept = "application/json"

loResp = CreateObject('Chilkat.HttpResponse')
lnSuccess = loHttp.HttpNoBody("GET","https://www.googleapis.com/gmail/v1/users/userId/messages",loResp)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loResp
    CANCEL
ENDIF

? "Response Status Code: " + STR(loResp.StatusCode)

loJsonResponse = CreateObject('Chilkat.JsonObject')
loJsonResponse.Load(loResp.BodyStr)
loJsonResponse.EmitCompact = 0
? loJsonResponse.Emit()

IF (loResp.StatusCode <> 200) THEN
    ? "Failed."
    RELEASE loHttp
    RELEASE loResp
    RELEASE loJsonResponse
    CANCEL
ENDIF

* {
*   "messages": [
*     users.messages Resource
*   ],
*   "nextPageToken": string,
*   "resultSizeEstimate": unsigned integer
* }

lnResultSizeEstimate = loJsonResponse.IntOf("resultSizeEstimate")
i = 0
lnCount_i = loJsonResponse.SizeOfArray("messages")
DO WHILE i < lnCount_i
    loJsonResponse.I = i
    lcId = loJsonResponse.StringOf("messages[i].id")
    lcThreadId = loJsonResponse.StringOf("messages[i].threadId")
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loResp
RELEASE loJsonResponse