Not able to add predicate to selector with Google Adwords API

笑着哭i 提交于 2019-12-12 03:43:39

问题


I am using Google Adwords API version - 201603

While generating Criteria report, I am filtering the data using predicate. Here is the code where I am adding predicate to the selector to filter the data.

final Selector selector = new Selector();
selector.getFields().addAll(Lists.newArrayList("CampaignId",
    "AdGroupId",
    "Id",
    "CriteriaType",
    "Criteria",
    "FinalUrls",
    "Impressions",
    "Clicks",
    "Cost"));

final Predicate p=new Predicate();
p.setField("CriteriaType");
p.setOperator(PredicateOperator.CONTAINS_ANY);
p.getValues().add("Webpage");
final Collection<Predicate> predicates=new ArrayList<>();
predicates.add(p);
selector.getPredicates().add(p);

But when i run the code, I am getting below error.

       __rdxml: <?xml version="1.0" encoding="UTF-8" standalone="yes"?><reportDefinition xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201603"><ns2:selector><ns2:fields>CampaignId</ns2:fields><ns2:fields>AdGroupId</ns2:fields><ns2:fields>Id</ns2:fields><ns2:fields>CriteriaType</ns2:fields><ns2:fields>Criteria</ns2:fields><ns2:fields>FinalUrls</ns2:fields><ns2:fields>Impressions</ns2:fields><ns2:fields>Clicks</ns2:fields><ns2:fields>Cost</ns2:fields><ns2:predicates><ns2:field>CriteriaType</ns2:field><ns2:operator>CONTAINS_ANY</ns2:operator><ns2:values>Webpage</ns2:values></ns2:predicates></ns2:selector><ns2:reportName>Criteria performance report #1467042784488</ns2:reportName><ns2:reportType>CRITERIA_PERFORMANCE_REPORT</ns2:reportType><ns2:dateRangeType>ALL_TIME</ns2:dateRangeType><ns2:downloadFormat>CSV</ns2:downloadFormat></reportDefinition>

[27 Jun 2016 11:53:04,876-report_download:WARN:main] Response received with status code 400 and message: Bad Request

Report was not downloaded due to: HTTP Response Code: 400, FieldPath: selector, Trigger: CriteriaType, Type: SelectorError.INVALID_PREDICATE_OPERATOR

I am not able to figure out what is the error. If anyone has idea about what is going on. Please do answer the question.


回答1:


This operator only works with labels according to a member of the Adwords API team.

Seeing as you only have a single value in your predicate, couldn't you just use CONTAINS instead of CONTAINS_ANY?



来源:https://stackoverflow.com/questions/38060687/not-able-to-add-predicate-to-selector-with-google-adwords-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!