I wrote my update code like this. Is this code was right? I don't want
to merge the criterions which takes more conditions to check rather
than remove and add campaignCriterions.
require 'rubygems'
require 'adwords_api'
API_VERSION = :v201109
adwords = AdwordsApi::Api.new
campaign_criterion_srv =
adwords.service(:CampaignCriterionService, API_VERSION)
campaign_id = '562911'.to_i
fields = ["Address", "AgeRangeType", "Argument",
"CampaignId", "CarrierCountryCode", "CarrierName",
"ContentLabelType", "CriteriaType", "DisplayType",
"GenderType", "GeoPoint", "Id", "IsObsolete",
"KeywordMatchType", "KeywordText", "LanguageCode",
"LanguageName", "LocationName", "Operand", "ParentLocations",
"Path", "PlacementUrl", "PlatformName", "RadiusDistanceUnits",
"RadiusInUnits", "Text", "UserInterestId", "UserInterestName",
"UserListId", "UserListMembershipStatus", "UserListName",
"Vertices"]
selector = {
:predicates => [
:field => 'CampaignId',
:operator => 'EQUALS',
:values => [campaign_id]
],
:fields => fields
}
response = campaign_criterion_srv.get(selector)
existing_criterions = response[:entries]
new_criterions = [ {:xsi_type => 'Gender', :id => 10},
{:xsi_type => 'Gender', :id => 11}]
operations = []
if(!existing_criterions.empty?)
puts "aaaaaaaaaaaaaa #{existing_criterions}"
existing_criterions.each do |criterions|
criterion = criterions[:criterion]
if(criterion[:xsi_type] != "Platform")
criterion.keys.each do |key|
if(!(key == :id || key == :xsi_type))
criterion.delete(key)
end
operations << {
:operator => 'REMOVE',
:operand => {
:campaign_id => campaign_id,
:criterion => criterion
}
}
end
end
end
end
new_criterions.each do |new_criterion|
operations << {
:operator => 'ADD',
:operand => {
:xsi_type => 'NegativeCampaignCriterion',
:campaign_id => campaign_id,
:criterion => new_criterion
}
}
end
response = campaign_criterion_srv.mutate(operations)
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
http://adwordsapi.blogspot.com
http://groups.google.com/group/adwords-api
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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