use of com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface in project googleads-java-lib by googleads.
the class GetProductCategoryTaxonomy 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 constant data service.
ConstantDataServiceInterface constantDataService = adWordsServices.get(session, ConstantDataServiceInterface.class);
Selector selector = new SelectorBuilder().equals(ConstantDataField.Country, "US").build();
ProductBiddingCategoryData[] results = constantDataService.getProductBiddingCategoryData(selector);
// List of top level category nodes.
List<CategoryNode> rootCategories = new ArrayList<>();
// Map of category ID to category node for all categories found in the results.
Map<Long, CategoryNode> biddingCategories = Maps.newHashMap();
for (ProductBiddingCategoryData productBiddingCategoryData : results) {
Long id = productBiddingCategoryData.getDimensionValue().getValue();
String name = productBiddingCategoryData.getDisplayValue(0).getValue();
CategoryNode node = biddingCategories.get(id);
if (node == null) {
node = new CategoryNode(id, name);
biddingCategories.put(id, node);
} else if (node.name == null) {
// Ensure that the name attribute for the node is set. Name will be null for nodes added
// to biddingCategories as a result of being a parentNode below.
node.name = name;
}
if (productBiddingCategoryData.getParentDimensionValue() != null && productBiddingCategoryData.getParentDimensionValue().getValue() != null) {
Long parentId = productBiddingCategoryData.getParentDimensionValue().getValue();
CategoryNode parentNode = biddingCategories.get(parentId);
if (parentNode == null) {
parentNode = new CategoryNode(parentId);
biddingCategories.put(parentId, parentNode);
}
parentNode.children.add(node);
} else {
rootCategories.add(node);
}
}
displayCategories(rootCategories, "");
}
use of com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface in project googleads-java-lib by googleads.
the class GetTargetableLanguagesAndCarriers 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 ConstantDataService.
ConstantDataServiceInterface constantDataService = adWordsServices.get(session, ConstantDataServiceInterface.class);
// Get all carriers.
Carrier[] carriers = constantDataService.getCarrierCriterion();
// Display results.
for (Carrier carrier : carriers) {
System.out.printf("Carrier with name '%s', ID %d, and country code '%s' was found.%n", carrier.getName(), carrier.getId(), carrier.getCountryCode());
}
// Get all languages.
Language[] languages = constantDataService.getLanguageCriterion();
// Display results.
for (Language language : languages) {
System.out.printf("Language with name '%s' and ID %d was found.%n", language.getName(), language.getId());
}
}
Aggregations