import; import; import; import; import; import; import; import; import; import; import; import*;

import*; import; import java.util.Collections; import java.util.List;

public class PostmasterToolsApiQuickStart { private static final String APPLICATION_NAME = "PostmasterTools API Java Quickstart"; private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance(); private static final String TOKENS_DIRECTORY_PATH = "tokens";

 * Global instance of the scopes required by this quickstart.
 * If modifying these scopes, delete your previously saved tokens/ folder.
private static final List<String> SCOPES = Collections.singletonList("");
private static final String CREDENTIALS_FILE_PATH = "/credentials.json";

 * Creates an authorized Credential object.
 * @param HTTP_TRANSPORT The network HTTP Transport.
 * @return An authorized Credential object.
 * @throws IOException If the credentials.json file cannot be found.
private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException {
    // Load client secrets.
    InputStream in = PostmasterToolsApiQuickStart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
    if (in == null) {
        throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(new FileDataStoreFactory(new
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8891).build();
    return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");

public static void main(String... args) throws IOException, GeneralSecurityException {
    // Build a new authorized API client service.
    final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    PostmasterTools postmasterTools = new PostmasterTools.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))

    List<Domain> domains =;
    if (domains == null || domains.isEmpty()) {
        System.out.println("No domains found!");
    } else {
        for (Domain domain : domains) {