JavaScript
JavaScript
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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat
v11.4.0 or greater.
var success = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
var http = new CkHttp();
http.AuthToken = "ACCESS_TOKEN";
http.Accept = "application/json";
var resp = new CkHttpResponse();
success = http.HttpNoBody("GET","https://www.googleapis.com/gmail/v1/users/userId/messages",resp);
if (success == false) {
console.log(http.LastErrorText);
return;
}
console.log("Response Status Code: " + resp.StatusCode);
var jsonResponse = new CkJsonObject();
jsonResponse.Load(resp.BodyStr);
jsonResponse.EmitCompact = false;
console.log(jsonResponse.Emit());
if (resp.StatusCode !== 200) {
console.log("Failed.");
return;
}
// {
// "messages": [
// users.messages Resource
// ],
// "nextPageToken": string,
// "resultSizeEstimate": unsigned integer
// }
var id;
var threadId;
var resultSizeEstimate = jsonResponse.IntOf("resultSizeEstimate");
var i = 0;
var count_i = jsonResponse.SizeOfArray("messages");
while (i < count_i) {
jsonResponse.I = i;
id = jsonResponse.StringOf("messages[i].id");
threadId = jsonResponse.StringOf("messages[i].threadId");
i = i+1;
}