Java
Chilkat2 Java
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 Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.HttpResponse;
import com.chilkatsoft.chilkat2.JsonObject;
public class ChilkatExample {
public static void main(String[] args) {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Http http = new Http();
http.setAuthToken("ACCESS_TOKEN");
http.setAccept("application/json");
HttpResponse resp = new HttpResponse();
try {
http.httpNoBody("GET", "https://www.googleapis.com/gmail/v1/users/userId/messages", resp);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
System.out.println("Response Status Code: " + resp.getStatusCode());
JsonObject jsonResponse = new JsonObject();
jsonResponse.load(resp.getBodyStr());
jsonResponse.setEmitCompact(false);
System.out.println(jsonResponse.emit());
if (resp.getStatusCode() != 200) {
System.out.println("Failed.");
return;
}
// {
// "messages": [
// users.messages Resource
// ],
// "nextPageToken": string,
// "resultSizeEstimate": unsigned integer
// }
String id = "";
String threadId = "";
int resultSizeEstimate = jsonResponse.intOf("resultSizeEstimate");
int i = 0;
int count_i = jsonResponse.sizeOfArray("messages");
while (i < count_i) {
jsonResponse.setI(i);
id = jsonResponse.stringOf("messages[i].id");
threadId = jsonResponse.stringOf("messages[i].threadId");
i = i + 1;
}
}
}