Java
Chilkat2 Java
List all Labels in the User's Mailbox
See more GMail REST API Examples
List all Labels in the GMail User's MailboxChilkat Java Downloads
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;
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("GMAIL-ACCESS-TOKEN");
String userId = "me";
http.setUrlVar("userId", userId);
String url = "https://www.googleapis.com/gmail/v1/users/{$userId}/labels";
http.setSessionLogFilename("c:/temp/qa_output/sessionLog.txt");
// Get the list of GMail labels as JSON.
StringBuilder sb = new StringBuilder();
try {
http.quickGetSb(url, sb);
} catch (ChilkatException e) {
System.out.println(e.getLastErrorText());
return;
}
JsonObject json = new JsonObject();
json.loadSb(sb);
json.setEmitCompact(false);
System.out.println(json.emit());
if (http.getLastStatus() != 200) {
System.out.println("Failed.");
return;
}
}
}