PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.pb"
Procedure ChilkatExample()
success.i = 0
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkAuthToken(http, "ACCESS_TOKEN")
CkHttp::setCkAccept(http, "application/json")
resp.i = CkHttpResponse::ckCreate()
If resp.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success = CkHttp::ckHttpNoBody(http,"GET","https://www.googleapis.com/gmail/v1/users/userId/messages",resp)
If success = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
ProcedureReturn
EndIf
Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp))
jsonResponse.i = CkJsonObject::ckCreate()
If jsonResponse.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(jsonResponse,CkHttpResponse::ckBodyStr(resp))
CkJsonObject::setCkEmitCompact(jsonResponse, 0)
Debug CkJsonObject::ckEmit(jsonResponse)
If CkHttpResponse::ckStatusCode(resp) <> 200
Debug "Failed."
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndIf
; {
; "messages": [
; users.messages Resource
; ],
; "nextPageToken": string,
; "resultSizeEstimate": unsigned integer
; }
id.s
threadId.s
resultSizeEstimate.i = CkJsonObject::ckIntOf(jsonResponse,"resultSizeEstimate")
i.i = 0
count_i.i = CkJsonObject::ckSizeOfArray(jsonResponse,"messages")
While i < count_i
CkJsonObject::setCkI(jsonResponse, i)
id = CkJsonObject::ckStringOf(jsonResponse,"messages[i].id")
threadId = CkJsonObject::ckStringOf(jsonResponse,"messages[i].threadId")
i = i + 1
Wend
CkHttp::ckDispose(http)
CkHttpResponse::ckDispose(resp)
CkJsonObject::ckDispose(jsonResponse)
ProcedureReturn
EndProcedure