google-adx-buyer-api 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog +4 -0
- data/README +5 -5
- data/examples/v201109/basic_operations/add_campaign.rb +4 -5
- data/examples/v201109/targeting/add_campaign_targeting_criteria.rb +2 -2
- data/examples/v201109_1/account_management/get_account_changes.rb +137 -0
- data/examples/v201109_1/basic_operations/add_ad_group.rb +88 -0
- data/examples/v201109_1/basic_operations/add_campaign.rb +98 -0
- data/examples/v201109_1/basic_operations/add_placements.rb +99 -0
- data/examples/v201109_1/basic_operations/add_thirdparty_redirect_ad.rb +105 -0
- data/examples/v201109_1/basic_operations/delete_ad.rb +80 -0
- data/examples/v201109_1/basic_operations/delete_ad_group.rb +76 -0
- data/examples/v201109_1/basic_operations/delete_campaign.rb +77 -0
- data/examples/v201109_1/basic_operations/delete_placement.rb +86 -0
- data/examples/v201109_1/basic_operations/get_ad_groups.rb +80 -0
- data/examples/v201109_1/basic_operations/get_campaigns.rb +77 -0
- data/examples/v201109_1/basic_operations/get_placements.rb +92 -0
- data/examples/v201109_1/basic_operations/get_thirdparty_redirect_ads.rb +100 -0
- data/examples/v201109_1/basic_operations/pause_ad.rb +81 -0
- data/examples/v201109_1/basic_operations/update_ad_group.rb +76 -0
- data/examples/v201109_1/basic_operations/update_campaign.rb +79 -0
- data/examples/v201109_1/basic_operations/update_placement.rb +94 -0
- data/examples/v201109_1/campaign_management/add_placements_in_bulk.rb +151 -0
- data/examples/v201109_1/campaign_management/get_all_disapproved_ads.rb +92 -0
- data/examples/v201109_1/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201109_1/error_handling/handle_partial_failures.rb +117 -0
- data/examples/v201109_1/error_handling/handle_policy_violation_error.rb +138 -0
- data/examples/v201109_1/error_handling/handle_two_factor_authorization_error.rb +87 -0
- data/examples/v201109_1/misc/get_all_images_and_videos.rb +101 -0
- data/examples/v201109_1/misc/upload_image.rb +87 -0
- data/examples/v201109_1/misc/use_oauth.rb +97 -0
- data/examples/v201109_1/optimization/get_placement_ideas.rb +106 -0
- data/examples/v201109_1/remarketing/add_audience.rb +111 -0
- data/examples/v201109_1/remarketing/add_conversion_tracker.rb +93 -0
- data/examples/v201109_1/reporting/download_criteria_report.rb +79 -0
- data/examples/v201109_1/reporting/download_defined_report.rb +67 -0
- data/examples/v201109_1/reporting/get_campaign_stats.rb +105 -0
- data/examples/v201109_1/reporting/get_defined_reports.rb +75 -0
- data/examples/v201109_1/reporting/get_report_fields.rb +71 -0
- data/examples/v201109_1/reporting/parallel_report_download.rb +159 -0
- data/examples/v201109_1/targeting/add_campaign_targeting_criteria.rb +110 -0
- data/examples/v201109_1/targeting/get_campaign_targeting_criteria.rb +104 -0
- data/examples/v201109_1/targeting/get_targetable_languages_and_carriers.rb +82 -0
- data/examples/v201109_1/targeting/lookup_location.rb +103 -0
- metadata +48 -11
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -6,8 +6,8 @@ AdWords and DoubleClick Ad Exchange Buyer API!
|
|
6
6
|
Please note that this is an early PREVIEW of the client library, still under
|
7
7
|
development.
|
8
8
|
|
9
|
-
It contains full support for v201109, with full stubs, and a
|
10
|
-
programming interface that lets you handle everything in native Ruby
|
9
|
+
It contains full support for v201109 and v201109_1, with full stubs, and a
|
10
|
+
simplified programming interface that lets you handle everything in native Ruby
|
11
11
|
collections.
|
12
12
|
|
13
13
|
|
@@ -27,8 +27,8 @@ Buyer client library examples. You need the AdWords library in order to use it
|
|
27
27
|
which is installed automatically as a dependency.
|
28
28
|
|
29
29
|
The following gem libraries are required:
|
30
|
-
- savon
|
31
|
-
- google-ads-common
|
30
|
+
- savon;
|
31
|
+
- google-ads-common.
|
32
32
|
|
33
33
|
|
34
34
|
== 2 - Using the client library:
|
@@ -61,7 +61,7 @@ You can also pass API a manually constructed config hash like:
|
|
61
61
|
})
|
62
62
|
|
63
63
|
Then, just specify which service you're looking to use, and which version:
|
64
|
-
campaign_srv = adwords.service(:CampaignService, :
|
64
|
+
campaign_srv = adwords.service(:CampaignService, :v201109_1)
|
65
65
|
|
66
66
|
and you should now be able to just use the API methods in the object you were
|
67
67
|
returned:
|
@@ -60,11 +60,10 @@ def add_campaign()
|
|
60
60
|
:target_search_network => false,
|
61
61
|
:target_content_network => true,
|
62
62
|
:target_content_contextual => false
|
63
|
-
}
|
64
|
-
:settings =>
|
65
|
-
:xsi_type => 'RealTimeBiddingSetting',
|
66
|
-
|
67
|
-
}
|
63
|
+
},
|
64
|
+
:settings => [
|
65
|
+
{:xsi_type => 'RealTimeBiddingSetting', :opt_in => 'true'}
|
66
|
+
]
|
68
67
|
}
|
69
68
|
}
|
70
69
|
|
@@ -61,11 +61,11 @@ def add_campaign_targeting_criteria(campaign_id)
|
|
61
61
|
}
|
62
62
|
end
|
63
63
|
|
64
|
-
# Create operation to add a placement.
|
64
|
+
# Create operation to add a negative campaign placement.
|
65
65
|
operations << {
|
66
66
|
:operator => 'ADD',
|
67
67
|
:operand => {
|
68
|
-
:xsi_type => '
|
68
|
+
:xsi_type => 'NegativeCampaignCriterion',
|
69
69
|
:campaign_id => campaign_id,
|
70
70
|
:criterion => {
|
71
71
|
:xsi_type => 'Placement',
|
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example gets all account changes that happened within the last 24 hours,
|
22
|
+
# for all your campaigns.
|
23
|
+
#
|
24
|
+
# Tags: CustomerSyncService.get
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
require 'date'
|
28
|
+
require 'pp'
|
29
|
+
|
30
|
+
def get_account_changes()
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
|
35
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
36
|
+
# the configuration file or provide your own logger:
|
37
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
38
|
+
|
39
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
40
|
+
customer_sync_srv = adwords.service(:CustomerSyncService, API_VERSION)
|
41
|
+
|
42
|
+
today_at_midnight = DateTime.parse(Date.today.to_s)
|
43
|
+
yesterday_at_midnight = DateTime.parse((Date.today - 1).to_s)
|
44
|
+
min_date_time = yesterday_at_midnight.strftime("%Y%m%d %H%M%S")
|
45
|
+
max_date_time = today_at_midnight.strftime("%Y%m%d %H%M%S")
|
46
|
+
|
47
|
+
# Get all the campaigns for this account.
|
48
|
+
selector = {
|
49
|
+
:fields => ['Id']
|
50
|
+
}
|
51
|
+
response = campaign_srv.get(selector)
|
52
|
+
|
53
|
+
campaign_ids = []
|
54
|
+
|
55
|
+
if response and response[:entries]
|
56
|
+
campaign_ids = response[:entries].map { |campaign| campaign[:id] }
|
57
|
+
else
|
58
|
+
raise StandardError, 'No campaigns were found.'
|
59
|
+
end
|
60
|
+
|
61
|
+
# Create a selector for CustomerSyncService.
|
62
|
+
selector = {
|
63
|
+
:campaign_ids => campaign_ids,
|
64
|
+
:date_time_range => {
|
65
|
+
:min => min_date_time,
|
66
|
+
:max => max_date_time
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
# Get all account changes for the campaigns.
|
71
|
+
campaign_changes = customer_sync_srv.get(selector)
|
72
|
+
|
73
|
+
# Display changes.
|
74
|
+
if campaign_changes
|
75
|
+
puts "Most recent change: %s" % campaign_changes[:last_change_timestamp]
|
76
|
+
campaign_changes[:changed_campaigns].each do |campaign|
|
77
|
+
puts "Campaign with ID %d was changed:" % campaign[:campaign_id]
|
78
|
+
puts "\tCampaign change status: '%s'" % campaign[:campaign_change_status]
|
79
|
+
unless ['NEW', 'FIELDS_UNCHANGED'].include?(
|
80
|
+
campaign[:campaign_change_status])
|
81
|
+
puts "\tAdded ad extensions: '%s'" %
|
82
|
+
campaign[:added_ad_extensions].pretty_inspect.chomp
|
83
|
+
puts "\tAdded campaign criteria: '%s'" %
|
84
|
+
campaign[:added_campaign_criteria].pretty_inspect.chomp
|
85
|
+
puts "\tAdded campaign targeting: '%s'" %
|
86
|
+
campaign[:campaign_targeting_changed].pretty_inspect.chomp
|
87
|
+
puts "\tDeleted ad extensions: '%s'" %
|
88
|
+
campaign[:deleted_ad_extensions].pretty_inspect.chomp
|
89
|
+
puts "\tDeleted campaign criteria: '%s'" %
|
90
|
+
campaign[:deleted_campaign_criteria].pretty_inspect.chomp
|
91
|
+
|
92
|
+
if campaign[:changed_ad_groups]
|
93
|
+
campaign[:changed_ad_groups].each do |ad_group|
|
94
|
+
puts "\tAd group with ID %d was changed:" % ad_group[:ad_group_id]
|
95
|
+
puts "\t\tAd group changed status: '%s'" %
|
96
|
+
ad_group[:ad_group_change_status]
|
97
|
+
unless ['NEW', 'FIELDS_UNCHANGED'].include?(
|
98
|
+
ad_group[:ad_group_change_status])
|
99
|
+
puts "\t\tAds changed: '%s'" %
|
100
|
+
ad_group[:changed_ads].pretty_inspect.chomp
|
101
|
+
puts "\t\tCriteria changed: '%s'" %
|
102
|
+
ad_group[:changed_criteria].pretty_inspect.chomp
|
103
|
+
puts "\t\tCriteria deleted: '%s'" %
|
104
|
+
ad_group[:deleted_criteria].pretty_inspect.chomp
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
puts
|
110
|
+
end
|
111
|
+
else
|
112
|
+
puts 'No account changes were found.'
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if __FILE__ == $0
|
117
|
+
API_VERSION = :v201109_1
|
118
|
+
|
119
|
+
begin
|
120
|
+
get_account_changes()
|
121
|
+
|
122
|
+
# HTTP errors.
|
123
|
+
rescue AdsCommon::Errors::HttpError => e
|
124
|
+
puts "HTTP Error: %s" % e
|
125
|
+
|
126
|
+
# API errors.
|
127
|
+
rescue AdwordsApi::Errors::ApiException => e
|
128
|
+
puts "Message: %s" % e.message
|
129
|
+
puts 'Errors:'
|
130
|
+
e.errors.each_with_index do |error, index|
|
131
|
+
puts "\tError [%d]:" % (index + 1)
|
132
|
+
error.each do |field, value|
|
133
|
+
puts "\t\t%s: %s" % [field, value]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example illustrates how to create an ad group. To create a campaign, run
|
22
|
+
# add_campaign.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_ad_group(campaign_id)
|
29
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
30
|
+
# when called without parameters.
|
31
|
+
adwords = AdwordsApi::Api.new
|
32
|
+
|
33
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
34
|
+
# the configuration file or provide your own logger:
|
35
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
36
|
+
|
37
|
+
ad_group_srv = adwords.service(:AdGroupService, API_VERSION)
|
38
|
+
|
39
|
+
# Prepare for adding ad group.
|
40
|
+
operation = {
|
41
|
+
:operator => 'ADD',
|
42
|
+
:operand => {
|
43
|
+
:name => 'Earth to Mars Cruises #%s' % (Time.new.to_f * 1000).to_i,
|
44
|
+
:status => 'ENABLED',
|
45
|
+
:campaign_id => campaign_id,
|
46
|
+
:bids => {
|
47
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the object
|
48
|
+
# being created. It's only necessary when you must provide an explicit
|
49
|
+
# type that the client library can't infer.
|
50
|
+
:xsi_type => 'ManualCPMAdGroupBids',
|
51
|
+
:max_cpc => {
|
52
|
+
:amount => {
|
53
|
+
:micro_amount => 10000000
|
54
|
+
}
|
55
|
+
}
|
56
|
+
},
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
# Add ad group.
|
61
|
+
response = ad_group_srv.mutate([operation])
|
62
|
+
ad_group = response[:value].first
|
63
|
+
puts "Ad group ID %d was successfully added." % ad_group[:id]
|
64
|
+
end
|
65
|
+
|
66
|
+
if __FILE__ == $0
|
67
|
+
API_VERSION = :v201109_1
|
68
|
+
|
69
|
+
begin
|
70
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
71
|
+
add_ad_group(campaign_id)
|
72
|
+
|
73
|
+
# HTTP errors.
|
74
|
+
rescue AdsCommon::Errors::HttpError => e
|
75
|
+
puts "HTTP Error: %s" % e
|
76
|
+
|
77
|
+
# API errors.
|
78
|
+
rescue AdwordsApi::Errors::ApiException => e
|
79
|
+
puts "Message: %s" % e.message
|
80
|
+
puts 'Errors:'
|
81
|
+
e.errors.each_with_index do |error, index|
|
82
|
+
puts "\tError [%d]:" % (index + 1)
|
83
|
+
error.each do |field, value|
|
84
|
+
puts "\t\t%s: %s" % [field, value]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example illustrates how to create a campaign.
|
22
|
+
#
|
23
|
+
# Tags: CampaignService.mutate
|
24
|
+
|
25
|
+
require 'adwords_api'
|
26
|
+
|
27
|
+
def add_campaign()
|
28
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
29
|
+
# when called without parameters.
|
30
|
+
adwords = AdwordsApi::Api.new
|
31
|
+
|
32
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
33
|
+
# the configuration file or provide your own logger:
|
34
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
35
|
+
|
36
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
37
|
+
|
38
|
+
# Prepare for adding campaign.
|
39
|
+
operation = {
|
40
|
+
:operator => 'ADD',
|
41
|
+
:operand => {
|
42
|
+
:name => 'Interplanetary Cruise #%s' % (Time.new.to_f * 1000).to_i,
|
43
|
+
:status => 'PAUSED',
|
44
|
+
:bidding_strategy => {
|
45
|
+
# The 'xsi_type' field allows you to specify the xsi:type of the object
|
46
|
+
# being created. It's only necessary when you must provide an explicit
|
47
|
+
# type that the client library can't infer.
|
48
|
+
:xsi_type => 'ManualCPM'
|
49
|
+
},
|
50
|
+
:budget => {
|
51
|
+
:period => 'DAILY',
|
52
|
+
:amount => {
|
53
|
+
:micro_amount => 50000000
|
54
|
+
},
|
55
|
+
:delivery_method => 'STANDARD'
|
56
|
+
},
|
57
|
+
# Set the campaign network options to Search and Search Network.
|
58
|
+
:network_setting => {
|
59
|
+
:target_google_search => false,
|
60
|
+
:target_search_network => false,
|
61
|
+
:target_content_network => true,
|
62
|
+
:target_content_contextual => false
|
63
|
+
},
|
64
|
+
:settings => [
|
65
|
+
{:xsi_type => 'RealTimeBiddingSetting', :opt_in => 'true'}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
}
|
69
|
+
|
70
|
+
# Add campaign.
|
71
|
+
response = campaign_srv.mutate([operation])
|
72
|
+
campaign = response[:value].first
|
73
|
+
puts "Campaign with name '%s' and ID %d was added." %
|
74
|
+
[campaign[:name], campaign[:id]]
|
75
|
+
end
|
76
|
+
|
77
|
+
if __FILE__ == $0
|
78
|
+
API_VERSION = :v201109_1
|
79
|
+
|
80
|
+
begin
|
81
|
+
add_campaign()
|
82
|
+
|
83
|
+
# HTTP errors.
|
84
|
+
rescue AdsCommon::Errors::HttpError => e
|
85
|
+
puts "HTTP Error: %s" % e
|
86
|
+
|
87
|
+
# API errors.
|
88
|
+
rescue AdwordsApi::Errors::ApiException => e
|
89
|
+
puts "Message: %s" % e.message
|
90
|
+
puts 'Errors:'
|
91
|
+
e.errors.each_with_index do |error, index|
|
92
|
+
puts "\tError [%d]:" % (index + 1)
|
93
|
+
error.each do |field, value|
|
94
|
+
puts "\t\t%s: %s" % [field, value]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
|
+
#
|
8
|
+
# License:: Licensed under the Apache License, Version 2.0 (the "License");
|
9
|
+
# you may not use this file except in compliance with the License.
|
10
|
+
# You may obtain a copy of the License at
|
11
|
+
#
|
12
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
13
|
+
#
|
14
|
+
# Unless required by applicable law or agreed to in writing, software
|
15
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
16
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
17
|
+
# implied.
|
18
|
+
# See the License for the specific language governing permissions and
|
19
|
+
# limitations under the License.
|
20
|
+
#
|
21
|
+
# This example illustrates how to add a placement to a given ad group. To create
|
22
|
+
# an ad group, run add_ad_group.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupCriterionService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_placements(ad_group_id)
|
29
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
30
|
+
# when called without parameters.
|
31
|
+
adwords = AdwordsApi::Api.new
|
32
|
+
|
33
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
34
|
+
# the configuration file or provide your own logger:
|
35
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
36
|
+
|
37
|
+
ad_group_criterion_srv =
|
38
|
+
adwords.service(:AdGroupCriterionService, API_VERSION)
|
39
|
+
|
40
|
+
# Create placements.
|
41
|
+
placements = [
|
42
|
+
{
|
43
|
+
:xsi_type => 'BiddableAdGroupCriterion',
|
44
|
+
:ad_group_id => ad_group_id,
|
45
|
+
:criterion => {
|
46
|
+
:xsi_type => 'Placement',
|
47
|
+
:url => 'http://mars.google.com'
|
48
|
+
}
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:xsi_type => 'BiddableAdGroupCriterion',
|
52
|
+
:ad_group_id => ad_group_id,
|
53
|
+
:criterion => {
|
54
|
+
:xsi_type => 'Placement',
|
55
|
+
:url => 'http://pluto.google.com'
|
56
|
+
}
|
57
|
+
},
|
58
|
+
]
|
59
|
+
|
60
|
+
# Create operations to add placements.
|
61
|
+
plc_operations = placements.map do |placement|
|
62
|
+
{:operator => 'ADD', :operand => placement}
|
63
|
+
end
|
64
|
+
|
65
|
+
# Add placements.
|
66
|
+
response = ad_group_criterion_srv.mutate(plc_operations)
|
67
|
+
ad_group_criteria = response[:value]
|
68
|
+
puts "Added %d placements to ad group ID %d." %
|
69
|
+
[ad_group_criteria.length, ad_group_id]
|
70
|
+
ad_group_criteria.each do |ad_group_criterion|
|
71
|
+
puts "\tPlacement ID is %d and type is '%s'." %
|
72
|
+
[ad_group_criterion[:criterion][:id],
|
73
|
+
ad_group_criterion[:criterion][:xsi_type]]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if __FILE__ == $0
|
78
|
+
API_VERSION = :v201109_1
|
79
|
+
|
80
|
+
begin
|
81
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
82
|
+
add_placements(ad_group_id)
|
83
|
+
|
84
|
+
# HTTP errors.
|
85
|
+
rescue AdsCommon::Errors::HttpError => e
|
86
|
+
puts "HTTP Error: %s" % e
|
87
|
+
|
88
|
+
# API errors.
|
89
|
+
rescue AdwordsApi::Errors::ApiException => e
|
90
|
+
puts "Message: %s" % e.message
|
91
|
+
puts 'Errors:'
|
92
|
+
e.errors.each_with_index do |error, index|
|
93
|
+
puts "\tError [%d]:" % (index + 1)
|
94
|
+
error.each do |field, value|
|
95
|
+
puts "\t\t%s: %s" % [field, value]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|