Hi,
I will be providing support in the meantime as Sreelakshmi is currently
OOO. To clarify, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE
<https://developers.google.com/adwords/api/docs/reference/v201605/AdGroupCriterionService.AdGroupCriterionError.Reason>
error
is observed when one tries to *ADD* as well as *EXCLUDE *a criteria to an
ad group at the same time. As an example, if you try to add the gender
criteria ID 11 to an ad group and also try to exclude the same criteria
(i.e. adding gender criteria ID 11 as a negative criteria) on the ad group,
you would receive this error. I would recommend comparing each criteria ID
that you are trying to add and exclude to the ad group with the criteria
IDs *already *associated with the ad group. As suggested by Sreelakshmi
earlier, you can use AdGroupCriterionService.get
<https://developers.google.com/adwords/api/docs/reference/v201609/AdGroupCriterionService#get>
to
check all criteria that are already defined on the ad group. If need be,
please try removing all criteria already defined on the ad group using
AdGroupCriterionService.mutate
<https://developers.google.com/adwords/api/docs/reference/v201609/AdGroupCriterionService#mutate>
and
try adding the criteria again.
To your question, if you plan to target males with the age range 18-24 and
25-34 in a single request, you can use the following code snippet:
Gender male = new Gender();
male.setId(10L);
AgeRange a18to24 = new AgeRange();
a18to24.setId(503001L);
AgeRange a25to34 = new AgeRange();
a25to34.setId(503002L);
BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new
BiddableAdGroupCriterion();
genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
genderBiddableAdGroupCriterion.setCriterion(male);
BiddableAdGroupCriterion a18to24BiddableAdGroupCriterion = new
BiddableAdGroupCriterion();
a18to24BiddableAdGroupCriterion.setAdGroupId(adGroupId);
a18to24BiddableAdGroupCriterion.setCriterion(a18to24);
BiddableAdGroupCriterion a25to34BiddableAdGroupCriterion = new
BiddableAdGroupCriterion();
a25to34BiddableAdGroupCriterion.setAdGroupId(adGroupId);
a25to34BiddableAdGroupCriterion.setCriterion(a25to34);
AdGroupCriterionOperation genderAdGroupCriterionOperation = new
AdGroupCriterionOperation();
genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
genderAdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation a18to24AdGroupCriterionOperation = new
AdGroupCriterionOperation();
a18to24AdGroupCriterionOperation.setOperand(a18to24BiddableAdGroupCriterion);
a18to24AdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionOperation a25to34AdGroupCriterionOperation = new
AdGroupCriterionOperation();
a25to34AdGroupCriterionOperation.setOperand(a25to34BiddableAdGroupCriterion);
a25to34AdGroupCriterionOperation.setOperator(Operator.ADD);
AdGroupCriterionReturnValue result =
adGroupCriterionService.mutate(new AdGroupCriterionOperation[] {
genderAdGroupCriterionOperation,
a18to24AdGroupCriterionOperation,
a25to34AdGroupCriterionOperation
});
If you are still facing issues, please revert with the SOAP XML request and
response logs for the API call and I would be happy to dig deeper.
Regards,
Vishal, AdWords API Team
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/dd6df4d7-6d74-4d83-bdf5-38e9723f4146%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.