use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class GetAllImagesAndVideos 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 MediaService.
MediaServiceInterface mediaService = adWordsServices.get(session, MediaServiceInterface.class);
int offset = 0;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(MediaField.MediaId, MediaField.Width, MediaField.Height, MediaField.MimeType).orderAscBy(MediaField.MediaId).offset(offset).limit(PAGE_SIZE).in(MediaField.Type, "IMAGE", "VIDEO").build();
MediaPage page = null;
do {
// Get all images.
page = mediaService.get(selector);
// Display images.
if (page != null && page.getEntries() != null) {
for (Media media : page.getEntries()) {
Map<MediaSize, Dimensions> dimensions = Maps.toMap(media.getDimensions());
System.out.printf("Media with ID %d, dimensions %s, and MIME type '%s' was found.%n", media.getMediaId(), toString(dimensions.get(MediaSize.FULL)), media.getMediaType());
}
} else {
System.out.println("No images/videos were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
} while (offset < page.getTotalNumEntries());
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class GetExpandedTextAds method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group to use to find expanded text ads.
* @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, Long adGroupId) throws RemoteException {
// Get the AdGroupAdService.
AdGroupAdServiceInterface adGroupAdService = adWordsServices.get(session, AdGroupAdServiceInterface.class);
int offset = 0;
boolean morePages = true;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(AdGroupAdField.Id, AdGroupAdField.Status, AdGroupAdField.HeadlinePart1, AdGroupAdField.HeadlinePart2, AdGroupAdField.Description).orderAscBy(AdGroupAdField.Id).offset(offset).limit(PAGE_SIZE).equals(AdGroupAdField.AdGroupId, adGroupId.toString()).in(AdGroupAdField.Status, "ENABLED", "PAUSED").equals("AdType", "EXPANDED_TEXT_AD").build();
while (morePages) {
// Get all ads.
AdGroupAdPage page = adGroupAdService.get(selector);
// Display ads.
if (page.getEntries() != null && page.getEntries().length > 0) {
for (AdGroupAd adGroupAd : page.getEntries()) {
ExpandedTextAd expandedTextAd = (ExpandedTextAd) adGroupAd.getAd();
System.out.printf("Expanded text ad with ID %d, status '%s', and headline '%s - %s' was found.%n", adGroupAd.getAd().getId(), adGroupAd.getStatus(), expandedTextAd.getHeadlinePart1(), expandedTextAd.getHeadlinePart2());
}
} else {
System.out.println("No expanded text ads were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
morePages = offset < page.getTotalNumEntries();
}
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class GetKeywords method runExample.
/**
* Runs the example.
*
* @param adWordsServices the services factory.
* @param session the session.
* @param adGroupId the ID of the ad group to use to find keywords.
* @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, Long adGroupId) throws RemoteException {
// Get the AdGroupCriterionService.
AdGroupCriterionServiceInterface adGroupCriterionService = adWordsServices.get(session, AdGroupCriterionServiceInterface.class);
int offset = 0;
boolean morePages = true;
// Create selector.
SelectorBuilder builder = new SelectorBuilder();
Selector selector = builder.fields(AdGroupCriterionField.Id, AdGroupCriterionField.CriteriaType, AdGroupCriterionField.KeywordMatchType, AdGroupCriterionField.KeywordText).orderAscBy(AdGroupCriterionField.KeywordText).offset(offset).limit(PAGE_SIZE).in(AdGroupCriterionField.AdGroupId, adGroupId.toString()).in(AdGroupCriterionField.CriteriaType, "KEYWORD").build();
while (morePages) {
// Get all ad group criteria.
AdGroupCriterionPage page = adGroupCriterionService.get(selector);
// Display ad group criteria.
if (page.getEntries() != null && page.getEntries().length > 0) {
// Display results.
Arrays.stream(page.getEntries()).map(adGroupCriterionResult -> (Keyword) adGroupCriterionResult.getCriterion()).forEach(keyword -> System.out.printf("Keyword with text '%s', match type '%s', criteria type '%s'," + " and ID %d was found.%n", keyword.getText(), keyword.getMatchType(), keyword.getType(), keyword.getId()));
} else {
System.out.println("No ad group criteria were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
morePages = offset < page.getTotalNumEntries();
}
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testSelectorBuilderImmutability.
/**
* Tests the immutability of the selector.
*/
@Test
public void testSelectorBuilderImmutability() {
DateFormat dateFormat = new SimpleDateFormat(SelectorBuilderImpl.DEFAULT_DATE_FORMAT);
SelectorBuilder builder = new SelectorBuilder();
DateTime start = new DateTime(2013, 3, 25, 0, 0, 0, 0);
DateTime end = new DateTime(2013, 3, 26, 0, 0, 0, 0);
String formatStart = dateFormat.format(start.toDate());
String formatEnd = dateFormat.format(end.toDate());
builder = builder.fields("Id", "Name", "Status").forDateRange(start, end);
Selector selector = builder.build();
assertEquals(formatStart, selector.getDateRange().getMin());
assertEquals(formatEnd, selector.getDateRange().getMax());
String formatEndPlusOne = dateFormat.format(end.plusDays(1).toDate());
DateRange dateRange = new DateRange();
dateRange.setMin(formatStart);
dateRange.setMax(formatEndPlusOne);
selector.setDateRange(dateRange);
assertEquals(formatStart, selector.getDateRange().getMin());
assertEquals(formatEndPlusOne, selector.getDateRange().getMax());
Selector selectorRebuilt = builder.fields("Id", "Name", "Status").forDateRange(start, end).build();
assertEquals(formatStart, selectorRebuilt.getDateRange().getMin());
assertEquals(formatEnd, selectorRebuilt.getDateRange().getMax());
checkUtilitiesState(false);
}
use of com.google.api.ads.adwords.jaxws.v201809.cm.Selector in project googleads-java-lib by googleads.
the class SelectorBuilderTest method testFieldsRemove.
/**
* Tests the removal of a new field.
*/
@Test
public void testFieldsRemove() {
SelectorBuilder builder = new SelectorBuilder();
builder = builder.fields("Id", "Name", "Status", "StartDate", "EndDate", "ServingStatus", "Settings");
Selector selector = builder.build();
assertEquals(7, selector.getFields().length);
assertEquals("Id", selector.getFields()[0]);
assertEquals("Name", selector.getFields()[1]);
assertEquals("Status", selector.getFields()[2]);
assertEquals("StartDate", selector.getFields()[3]);
assertEquals("EndDate", selector.getFields()[4]);
assertEquals("ServingStatus", selector.getFields()[5]);
assertEquals("Settings", selector.getFields()[6]);
checkUtilitiesState(false);
}
Aggregations