Search in sources :

Example 1 with ProductBiddingCategoryData

use of com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategoryData 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, "");
}
Also used : SelectorBuilder(com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder) ArrayList(java.util.ArrayList) ConstantDataServiceInterface(com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface) ProductBiddingCategoryData(com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategoryData) Selector(com.google.api.ads.adwords.axis.v201809.cm.Selector)

Aggregations

SelectorBuilder (com.google.api.ads.adwords.axis.utils.v201809.SelectorBuilder)1 ConstantDataServiceInterface (com.google.api.ads.adwords.axis.v201809.cm.ConstantDataServiceInterface)1 ProductBiddingCategoryData (com.google.api.ads.adwords.axis.v201809.cm.ProductBiddingCategoryData)1 Selector (com.google.api.ads.adwords.axis.v201809.cm.Selector)1 ArrayList (java.util.ArrayList)1