use of com.google.api.ads.adwords.axis.v201809.ch.CustomerChangeData in project googleads-java-lib by googleads.
the class GetAccountChanges method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @throws ApiException if the API request failed with one or more service errors.
* @throws RemoteException if the API request failed due to other errors.
*/
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
// Get the CampaignService.
CampaignServiceInterface campaignService = adWordsServices.get(session, CampaignServiceInterface.class);
// Get the CustomerSyncService.
CustomerSyncServiceInterface customerSyncService = adWordsServices.get(session, CustomerSyncServiceInterface.class);
// Get a list of all campaign IDs.
List<Long> campaignIds = new ArrayList<>();
Selector selector = new SelectorBuilder().fields(CampaignField.Id).build();
CampaignPage campaigns = campaignService.get(selector);
if (campaigns.getEntries() != null) {
Arrays.stream(campaigns.getEntries()).forEach(campaign -> campaignIds.add(campaign.getId()));
}
// Create date time range for the past 24 hours.
DateTimeRange dateTimeRange = new DateTimeRange();
dateTimeRange.setMin(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24)));
dateTimeRange.setMax(new SimpleDateFormat("yyyyMMdd HHmmss").format(new Date()));
// Create selector.
CustomerSyncSelector customerSyncSelector = new CustomerSyncSelector();
customerSyncSelector.setDateTimeRange(dateTimeRange);
customerSyncSelector.setCampaignIds(ArrayUtils.toPrimitive(campaignIds.toArray(new Long[] {})));
// Get all account changes for campaign.
CustomerChangeData accountChanges = customerSyncService.get(customerSyncSelector);
// Display changes.
if (accountChanges != null && accountChanges.getChangedCampaigns() != null) {
System.out.printf("Most recent change: %s%n", accountChanges.getLastChangeTimestamp());
for (CampaignChangeData campaignChanges : accountChanges.getChangedCampaigns()) {
System.out.printf("Campaign with ID %d was changed:%n", campaignChanges.getCampaignId());
System.out.printf("\tCampaign changed status: '%s'%n", campaignChanges.getCampaignChangeStatus());
if (!ChangeStatus.NEW.equals(campaignChanges.getCampaignChangeStatus())) {
System.out.printf("\tAdded campaign criteria: %s%n", getFormattedList(campaignChanges.getAddedCampaignCriteria()));
System.out.printf("\tRemoved campaign criteria: %s%n", getFormattedList(campaignChanges.getRemovedCampaignCriteria()));
if (campaignChanges.getChangedAdGroups() != null) {
for (AdGroupChangeData adGroupChanges : campaignChanges.getChangedAdGroups()) {
System.out.printf("\tAd group with ID %d was changed:%n", adGroupChanges.getAdGroupId());
System.out.printf("\t\tAd group changed status: %s%n", adGroupChanges.getAdGroupChangeStatus());
if (!ChangeStatus.NEW.equals(adGroupChanges.getAdGroupChangeStatus())) {
System.out.printf("\t\tAds changed: %s%n", getFormattedList(adGroupChanges.getChangedAds()));
System.out.printf("\t\tCriteria changed: %s%n", getFormattedList(adGroupChanges.getChangedCriteria()));
System.out.printf("\t\tCriteria removed: %s%n", getFormattedList(adGroupChanges.getRemovedCriteria()));
}
}
}
}
System.out.println("");
}
} else {
System.out.println("No account changes were found.");
}
}
Aggregations