Hi Bharani,
Thank you for the response! I just tested with this code and if my operator
is "ADD" I get a duplicate adgroup name error, and if my operator is "SET"
I don't get an error, but it's still set to Observation, and not Targeting.
public void updateTargeting(AdWordsServicesInterface adWordsServices,
AdWordsSession session, AdGroup adGroup) {
AdGroupServiceInterface adGroupService = adWordsServices.get(session,
AdGroupServiceInterface.class);
List<Setting> settings = Lists.newArrayList();
List<TargetingSettingDetail> details = Lists.newArrayList();
TargetingSetting targetingSetting = null;
if (adGroup.getSettings() != null) {
// Find the existing TargetingSetting if it exists, and keep
// track of all other settings.
for (Setting setting : adGroup.getSettings()) {
if (setting instanceof TargetingSetting) {
targetingSetting = (TargetingSetting) setting;
} else {
settings.add(setting);
}
}
if (targetingSetting != null) {
// Copy all the existing TargetingSettingDetails except the one for
// USER_INTEREST_AND_LIST.
for (TargetingSettingDetail settingDetail : targetingSetting.getDetails
()) {
if (!CriterionTypeGroup.USER_INTEREST_AND_LIST.equals(
settingDetail.getCriterionTypeGroup())) {
details.add(settingDetail);
}
}
}
}
if (targetingSetting == null) {
targetingSetting = new TargetingSetting();
}
// Create a new USER_INTEREST_AND_LIST targeting setting detail and add
// it to the details list.
TargetingSettingDetail userListsSetting = new TargetingSettingDetail();
userListsSetting.setCriterionTypeGroup(CriterionTypeGroup.
USER_INTEREST_AND_LIST);
// true = "Bid only"; false = "Target and bid"
userListsSetting.setTargetAll(true);
details.add(userListsSetting);
targetingSetting.setDetails(details.toArray(new TargetingSettingDetail[
details.size()]));
// Add the new TargetingSetting for USER_INTEREST_AND_LIST to the settings
list.
settings.add(targetingSetting);
adGroup.setSettings(settings.toArray(new Setting[settings.size()]));
// Create operations
AdGroupOperation operation = new AdGroupOperation();
operation.setOperand(adGroup);
operation.setOperator(Operator.SET);
AdGroupOperation[] operations = new AdGroupOperation[] {operation};
// Update settings by sending operations
try {
AdGroupReturnValue result = adGroupService.mutate(operations);
} catch (RemoteException e) {
logger.error("Error updating ad group settings: " + e);
}
}
On Thursday, May 9, 2019 at 3:12:41 PM UTC-5, googleadsapi-forumadvisor
wrote:
>
> Hi Josh,
>
> You may use the AdGroupService.mutate() operation with the
> TargetingSettingDetail
> <https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupService.TargetingSettingDetail>
> and
> targetAll set to true/false to switch between Observation and Targeting.
> You may refer to the code snippets available here
> <https://developers.google.com/adwords/api/docs/guides/remarketing#targeting_settings_for_remarketing>
> as
> a reference. Could you please give this a try?
>
> Thanks,
> Bharani, Google Ads API Team
> =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
> Also find us on our blog and discussion group:
> https://ads-developers.googleblog.com/search/label/google_ads_api
> https://developers.google.com/adwords/api/community/
> =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads 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 and Google Ads 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/e17ec976-53a7-4424-a823-74ea9711dff5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.