Sample code for 30+ languages & platforms
B4X

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 B4X Downloads

B4X
Dim success As Boolean = False

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

Dim http As ChilkatHttp
http.Initialize("http")

http.AuthToken = "ACCESS_TOKEN"

http.Accept = "application/json"

Dim resp As ChilkatHttpResponse
resp.Initialize
success = http.HttpNoBody("GET", "https://www.googleapis.com/gmail/v1/users/userId/messages", resp)
If success = False Then
    Log(http.LastErrorText)
    Return
End If


Log("Response Status Code: " & resp.StatusCode)

Dim jsonResponse As ChilkatJsonObject
jsonResponse.Initialize
jsonResponse.Load(resp.BodyStr)
jsonResponse.EmitCompact = False
Log(jsonResponse.Emit)

If resp.StatusCode <> 200 Then
    Log("Failed.")
    Return
End If


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



Dim id As String
Dim threadId As String

Dim resultSizeEstimate As Int = jsonResponse.IntOf("resultSizeEstimate")
Dim i As Int = 0
Dim count_i As Int = jsonResponse.SizeOfArray("messages")
Do While i < count_i
    jsonResponse.I = i
    id = jsonResponse.StringOf("messages[i].id")
    threadId = jsonResponse.StringOf("messages[i].threadId")
    i = i + 1
Loop