Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
http.authToken = "ACCESS_TOKEN"
http.accept = "application/json"
let resp = CkoHttpResponse()!
success = http.httpNoBody(verb: "GET", url: "https://www.googleapis.com/gmail/v1/users/userId/messages", response: resp)
if success == false {
print("\(http.lastErrorText!)")
return
}
print("Response Status Code: \(resp.statusCode.intValue)")
let jsonResponse = CkoJsonObject()!
jsonResponse.load(json: resp.bodyStr)
jsonResponse.emitCompact = false
print("\(jsonResponse.emit()!)")
if resp.statusCode.intValue != 200 {
print("Failed.")
return
}
// {
// "messages": [
// users.messages Resource
// ],
// "nextPageToken": string,
// "resultSizeEstimate": unsigned integer
// }
var id: String?
var threadId: String?
var resultSizeEstimate: Int = jsonResponse.int(of: "resultSizeEstimate").intValue
var i: Int = 0
var count_i: Int = jsonResponse.size(ofArray: "messages").intValue
while i < count_i {
jsonResponse.i = i
id = jsonResponse.string(of: "messages[i].id")
threadId = jsonResponse.string(of: "messages[i].threadId")
i = i + 1
}
}