throw new InvalidCredentialsException("You must have one or more profiles defined in Google Analytics in order to continue.");
}
}
public List<JSONObject> getProfiles() throws IOException {
Analytics analytics = initializeAnalytics();
Accounts accounts = analytics.management().accounts().list().execute();
List<JSONObject> jsonProfiles = Lists.newArrayList();
if (accounts.getItems().isEmpty()) {
System.err.println("No accounts found");
}
else {
for (Account account : accounts.getItems()) {
String accountId = account.getId();
// Query webproperties collection.
Webproperties webproperties = analytics.management().webproperties().list(accountId).execute();
if (webproperties.getItems().isEmpty()) {
System.err.println("No Webproperties found");
}
else {
for (Webproperty webproperty : webproperties.getItems()) {
String webpropertyId = webproperty.getId();
// Query profiles collection.
Profiles profiles = analytics.management().profiles().list(accountId, webpropertyId).execute();
if (profiles.getItems().isEmpty()) {
System.err.println("No profiles found");
}
else {
for (Profile profile : profiles.getItems()) {