如何使用AWQL或选择器阅读所有​​google adwords定位选项?

时间:2019-06-13 10:30:26

标签: java google-adwords

例如,我想阅读Google AdWords支持的年龄范围,性别,操作系统等。我想使用AWQL还是选择器阅读上述定位选项?

我可以使用ConstantDataService读取这些定位选项。

    AdWordsServicesInterface adWordsServices = AdWordsServices.getInstance();
    ConstantDataServiceInterface constantDataService =
        adWordsServices.get(this.session, ConstantDataServiceInterface.class);
    AgeRange []ageRanges = constantDataService.getAgeRangeCriterion();
    for(AgeRange a : ageRanges) {
        System.out.println(a.getId() + " :: " + a.getAgeRangeType() + " :: " + a.getCriterionType() + " :: " + a.getType());
    }

但是我无法应用过滤器。我看到可以使用AWQL或选择器来应用过滤器吗?我尝试了以下

    AdGroupCriterionServiceInterface adGroupCriterionService =
            adWordsServices.get(session, AdGroupCriterionServiceInterface.class);

    // Create selector.
    SelectorBuilder builder = new SelectorBuilder();
    Selector selector = builder
            .fields("Id", "AgeRangeType")
            .build();

    int PAGE_SIZE = 100;

    ServiceQuery serviceQuery = new ServiceQuery.Builder().fields(AdGroupCriterionField.Id, AdGroupCriterionField.AgeRangeType).limit(0, PAGE_SIZE).build();

    // Set selector paging = the most important change is to set numberResults to 0.
    AdGroupCriterionPage page = null;

    do {
        serviceQuery.nextPage(page);
        page = adGroupCriterionService.query(serviceQuery.toString());
        if (page.getEntries() != null) {
            for (AdGroupCriterion criterion : page.getEntries()) {
                System.out.printf("Campaign with name '%s' and ID %d was found.%n", criterion.getAdGroupCriterionType(),
                        criterion.getCriterion());
            }
        } else {
            System.out.println("No criterion were found.");
        }

    } while(serviceQuery.hasNext(page));

但无法正常工作。

有人可以告诉我如何使用AWQL或选择器阅读定位选项吗?

0 个答案:

没有答案