google-adx-buyer-api 0.4.3 → 0.4.4
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 +3 -3
- data/examples/v201209/account_management/get_account_changes.rb +137 -0
- data/examples/v201209/basic_operations/add_ad_group.rb +88 -0
- data/examples/v201209/basic_operations/add_campaign.rb +105 -0
- data/examples/v201209/basic_operations/add_placements.rb +99 -0
- data/examples/v201209/basic_operations/add_thirdparty_redirect_ad.rb +126 -0
- data/examples/v201209/basic_operations/delete_ad.rb +80 -0
- data/examples/{v201206/reporting/download_defined_report.rb → v201209/basic_operations/delete_ad_group.rb} +21 -12
- data/examples/v201209/basic_operations/delete_campaign.rb +77 -0
- data/examples/v201209/basic_operations/delete_placement.rb +86 -0
- data/examples/v201209/basic_operations/get_ad_groups.rb +80 -0
- data/examples/v201209/basic_operations/get_campaigns.rb +77 -0
- data/examples/v201209/basic_operations/get_placements.rb +92 -0
- data/examples/v201209/basic_operations/get_thirdparty_redirect_ads.rb +100 -0
- data/examples/v201209/basic_operations/pause_ad.rb +81 -0
- data/examples/v201209/basic_operations/update_ad_group.rb +76 -0
- data/examples/v201209/basic_operations/update_campaign.rb +79 -0
- data/examples/v201209/basic_operations/update_placement.rb +94 -0
- data/examples/v201209/campaign_management/add_placements_in_bulk.rb +151 -0
- data/examples/v201209/campaign_management/get_all_disapproved_ads.rb +92 -0
- data/examples/v201209/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201209/error_handling/handle_partial_failures.rb +117 -0
- data/examples/v201209/error_handling/handle_policy_violation_error.rb +138 -0
- data/examples/v201209/error_handling/handle_two_factor_authorization_error.rb +87 -0
- data/examples/v201209/misc/get_all_images_and_videos.rb +101 -0
- data/examples/v201209/misc/upload_image.rb +87 -0
- data/examples/v201209/misc/use_oauth.rb +97 -0
- data/examples/v201209/optimization/get_placement_ideas.rb +106 -0
- data/examples/v201209/remarketing/add_audience.rb +111 -0
- data/examples/v201209/remarketing/add_conversion_tracker.rb +93 -0
- data/examples/v201209/reporting/download_criteria_report.rb +79 -0
- data/examples/v201209/reporting/get_campaign_stats.rb +105 -0
- data/examples/{v201206/reporting/get_defined_reports.rb → v201209/reporting/get_report_fields.rb} +13 -17
- data/examples/v201209/reporting/parallel_report_download.rb +159 -0
- data/examples/v201209/targeting/add_campaign_targeting_criteria.rb +110 -0
- data/examples/v201209/targeting/get_campaign_targeting_criteria.rb +104 -0
- data/examples/v201209/targeting/get_targetable_languages_and_carriers.rb +82 -0
- data/examples/v201209/targeting/lookup_location.rb +104 -0
- metadata +89 -34
@@ -0,0 +1,77 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 retrieve all the campaigns for an account.
|
22
|
+
#
|
23
|
+
# Tags: CampaignService.get
|
24
|
+
|
25
|
+
require 'adwords_api'
|
26
|
+
|
27
|
+
def get_all_campaigns()
|
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
|
+
# Get all the campaigns for this account; empty selector.
|
39
|
+
selector = {
|
40
|
+
:fields => ['Id', 'Name', 'Status'],
|
41
|
+
:ordering => [{:field => 'Name', :sort_order => 'ASCENDING'}]
|
42
|
+
}
|
43
|
+
response = campaign_srv.get(selector)
|
44
|
+
|
45
|
+
if response and response[:entries]
|
46
|
+
campaigns = response[:entries]
|
47
|
+
campaigns.each do |campaign|
|
48
|
+
puts "Campaign name is \"#{campaign[:name]}\", id is #{campaign[:id]} " +
|
49
|
+
"and status is \"#{campaign[:status]}\"."
|
50
|
+
end
|
51
|
+
else
|
52
|
+
puts 'No campaigns were found.'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if __FILE__ == $0
|
57
|
+
API_VERSION = :v201209
|
58
|
+
|
59
|
+
begin
|
60
|
+
get_all_campaigns()
|
61
|
+
|
62
|
+
# HTTP errors.
|
63
|
+
rescue AdsCommon::Errors::HttpError => e
|
64
|
+
puts "HTTP Error: %s" % e
|
65
|
+
|
66
|
+
# API errors.
|
67
|
+
rescue AdwordsApi::Errors::ApiException => e
|
68
|
+
puts "Message: %s" % e.message
|
69
|
+
puts 'Errors:'
|
70
|
+
e.errors.each_with_index do |error, index|
|
71
|
+
puts "\tError [%d]:" % (index + 1)
|
72
|
+
error.each do |field, value|
|
73
|
+
puts "\t\t%s: %s" % [field, value]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,92 @@
|
|
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 retrieve all the placements for an ad group.
|
22
|
+
# To add a placement to an existing ad group, run add_placements.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupCriterionService.get
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def get_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
|
+
# Get all the criteria for this ad group.
|
41
|
+
selector = {
|
42
|
+
:fields => ['Id', 'PlacementUrl'],
|
43
|
+
:ordering => [
|
44
|
+
{:field => 'AdGroupId', :sort_order => 'ASCENDING'}
|
45
|
+
],
|
46
|
+
:predicates => [
|
47
|
+
{:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]},
|
48
|
+
{
|
49
|
+
:field => 'CriteriaType',
|
50
|
+
:operator => 'EQUALS',
|
51
|
+
:values => ['PLACEMENT']
|
52
|
+
}
|
53
|
+
]
|
54
|
+
}
|
55
|
+
response = ad_group_criterion_srv.get(selector)
|
56
|
+
if response and response[:entries]
|
57
|
+
ad_group_criteria = response[:entries]
|
58
|
+
puts "Ad group ID %d has %d placements." %
|
59
|
+
[ad_group_id, ad_group_criteria.length]
|
60
|
+
ad_group_criteria.each do |ad_group_criterion|
|
61
|
+
puts "\tPlacement ID is %d and URL is '%s'." %
|
62
|
+
[ad_group_criterion[:criterion][:id],
|
63
|
+
ad_group_criterion[:criterion][:placement_url]]
|
64
|
+
end
|
65
|
+
else
|
66
|
+
puts "No placements found for ad group ID %d" % ad_group_id
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if __FILE__ == $0
|
71
|
+
API_VERSION = :v201209
|
72
|
+
|
73
|
+
begin
|
74
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
75
|
+
get_placements(ad_group_id)
|
76
|
+
|
77
|
+
# HTTP errors.
|
78
|
+
rescue AdsCommon::Errors::HttpError => e
|
79
|
+
puts "HTTP Error: %s" % e
|
80
|
+
|
81
|
+
# API errors.
|
82
|
+
rescue AdwordsApi::Errors::ApiException => e
|
83
|
+
puts "Message: %s" % e.message
|
84
|
+
puts 'Errors:'
|
85
|
+
e.errors.each_with_index do |error, index|
|
86
|
+
puts "\tError [%d]:" % (index + 1)
|
87
|
+
error.each do |field, value|
|
88
|
+
puts "\t\t%s: %s" % [field, value]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2012, 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 retrieve all third party redirect ads for an
|
22
|
+
# ad group. To add third party redirect ad to an existing ad group, run
|
23
|
+
# add_thirdparty_redirect_ad.rb.
|
24
|
+
#
|
25
|
+
# Tags: AdGroupAdService.get
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
def get_all_ads(ad_group_id)
|
30
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
31
|
+
# when called without parameters.
|
32
|
+
adwords = AdwordsApi::Api.new
|
33
|
+
|
34
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
35
|
+
# the configuration file or provide your own logger:
|
36
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
37
|
+
|
38
|
+
ad_group_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
|
39
|
+
|
40
|
+
# Create selector to get all third party redirect ads for this ad group.
|
41
|
+
selector = {
|
42
|
+
:fields => ['Id', 'Status', 'Url', 'DisplayUrl'],
|
43
|
+
:ordering => [{:field => 'Id', :sort_order => 'ASCENDING'}],
|
44
|
+
# By default, disabled ads aren't returned by the selector. To return them,
|
45
|
+
# include the DISABLED status in a predicate.
|
46
|
+
:predicates => [
|
47
|
+
{:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]},
|
48
|
+
{
|
49
|
+
:field => 'Status',
|
50
|
+
:operator => 'IN',
|
51
|
+
:values => ['ENABLED', 'PAUSED', 'DISABLED']
|
52
|
+
},
|
53
|
+
{
|
54
|
+
:field => 'AdType',
|
55
|
+
:operator => 'EQUALS',
|
56
|
+
:values => ['THIRD_PARTY_REDIRECT_AD']
|
57
|
+
}
|
58
|
+
]
|
59
|
+
}
|
60
|
+
|
61
|
+
# Request the ads.
|
62
|
+
response = ad_group_ad_srv.get(selector)
|
63
|
+
if response and response[:entries]
|
64
|
+
ads = response[:entries]
|
65
|
+
puts "Ad group ID %d has %d third party redirect ads." %
|
66
|
+
[ad_group_id, ads.length]
|
67
|
+
ads.each do |ad|
|
68
|
+
puts "\tAd ID is %d, type is '%s', status is '%s'" %
|
69
|
+
[ad[:ad][:id], ad[:ad][:xsi_type], ad[:status]]
|
70
|
+
puts "\tURL: %s" % ad[:url]
|
71
|
+
puts "\tDisplay URL: %s" % ad[:display_url]
|
72
|
+
end
|
73
|
+
else
|
74
|
+
puts "No ads found for ad group ID %d." % ad_group_id
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if __FILE__ == $0
|
79
|
+
API_VERSION = :v201209
|
80
|
+
|
81
|
+
begin
|
82
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
83
|
+
get_all_ads(ad_group_id)
|
84
|
+
|
85
|
+
# HTTP errors.
|
86
|
+
rescue AdsCommon::Errors::HttpError => e
|
87
|
+
puts "HTTP Error: %s" % e
|
88
|
+
|
89
|
+
# API errors.
|
90
|
+
rescue AdwordsApi::Errors::ApiException => e
|
91
|
+
puts "Message: %s" % e.message
|
92
|
+
puts 'Errors:'
|
93
|
+
e.errors.each_with_index do |error, index|
|
94
|
+
puts "\tError [%d]:" % (index + 1)
|
95
|
+
error.each do |field, value|
|
96
|
+
puts "\t\t%s: %s" % [field, value]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,81 @@
|
|
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 pause an ad, setting its status to 'PAUSED'.
|
22
|
+
# To create ads, run add_thirdparty_redirect_ad.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupAdService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def pause_ad(ad_group_id, ad_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_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
|
38
|
+
|
39
|
+
# Prepare for updating ad.
|
40
|
+
operation = {
|
41
|
+
:operator => 'SET',
|
42
|
+
:operand => {
|
43
|
+
:ad_group_id => ad_group_id,
|
44
|
+
:status => 'PAUSED',
|
45
|
+
:ad => {
|
46
|
+
:id => ad_id
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
51
|
+
# Update ad.
|
52
|
+
response = ad_group_ad_srv.mutate([operation])
|
53
|
+
ad = response[:value].first
|
54
|
+
puts "Ad ID %d was successfully updated, status set to '%s'." %
|
55
|
+
[ad[:ad][:id], ad[:status]]
|
56
|
+
end
|
57
|
+
|
58
|
+
if __FILE__ == $0
|
59
|
+
API_VERSION = :v201209
|
60
|
+
|
61
|
+
begin
|
62
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
63
|
+
ad_id = 'INSERT_AD_ID_HERE'.to_i
|
64
|
+
pause_ad(ad_group_id, ad_id)
|
65
|
+
|
66
|
+
# HTTP errors.
|
67
|
+
rescue AdsCommon::Errors::HttpError => e
|
68
|
+
puts "HTTP Error: %s" % e
|
69
|
+
|
70
|
+
# API errors.
|
71
|
+
rescue AdwordsApi::Errors::ApiException => e
|
72
|
+
puts "Message: %s" % e.message
|
73
|
+
puts 'Errors:'
|
74
|
+
e.errors.each_with_index do |error, index|
|
75
|
+
puts "\tError [%d]:" % (index + 1)
|
76
|
+
error.each do |field, value|
|
77
|
+
puts "\t\t%s: %s" % [field, value]
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 update an ad group, setting its status to
|
22
|
+
# 'PAUSED'. To create an ad group, run add_ad_group.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def update_ad_group(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_srv = adwords.service(:AdGroupService, API_VERSION)
|
38
|
+
|
39
|
+
# Prepare for updating ad group.
|
40
|
+
operation = {
|
41
|
+
:operator => 'SET',
|
42
|
+
:operand => {
|
43
|
+
:status => 'PAUSED',
|
44
|
+
:id => ad_group_id
|
45
|
+
}
|
46
|
+
}
|
47
|
+
|
48
|
+
# Update ad group.
|
49
|
+
response = ad_group_srv.mutate([operation])
|
50
|
+
ad_group = response[:value].first
|
51
|
+
puts "Ad group ID %d was successfully updated." % ad_group[:id]
|
52
|
+
end
|
53
|
+
|
54
|
+
if __FILE__ == $0
|
55
|
+
API_VERSION = :v201209
|
56
|
+
|
57
|
+
begin
|
58
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
59
|
+
update_ad_group(ad_group_id)
|
60
|
+
|
61
|
+
# HTTP errors.
|
62
|
+
rescue AdsCommon::Errors::HttpError => e
|
63
|
+
puts "HTTP Error: %s" % e
|
64
|
+
|
65
|
+
# API errors.
|
66
|
+
rescue AdwordsApi::Errors::ApiException => e
|
67
|
+
puts "Message: %s" % e.message
|
68
|
+
puts 'Errors:'
|
69
|
+
e.errors.each_with_index do |error, index|
|
70
|
+
puts "\tError [%d]:" % (index + 1)
|
71
|
+
error.each do |field, value|
|
72
|
+
puts "\t\t%s: %s" % [field, value]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.sgomes@gmail.com (Sérgio Gomes)
|
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 update a campaign, setting its budget delivery
|
22
|
+
# to 'ACCELERATED'. To create a campaign, run add_campaign.rb.
|
23
|
+
#
|
24
|
+
# Tags: CampaignService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def update_campaign(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
|
+
campaign_srv = adwords.service(:CampaignService, API_VERSION)
|
38
|
+
|
39
|
+
# Prepare for updating campaign.
|
40
|
+
operation = {
|
41
|
+
:operator => 'SET',
|
42
|
+
:operand => {
|
43
|
+
:id => campaign_id,
|
44
|
+
:budget => {
|
45
|
+
:delivery_method => 'ACCELERATED'
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
# Update campaign.
|
51
|
+
response = campaign_srv.mutate([operation])
|
52
|
+
campaign = response[:value].first
|
53
|
+
puts "Campaign ID %d successfully updated, delivery method set to '%s'." %
|
54
|
+
[campaign[:id], campaign[:budget][:delivery_method]]
|
55
|
+
end
|
56
|
+
|
57
|
+
if __FILE__ == $0
|
58
|
+
API_VERSION = :v201209
|
59
|
+
|
60
|
+
begin
|
61
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
62
|
+
update_campaign(campaign_id)
|
63
|
+
|
64
|
+
# HTTP errors.
|
65
|
+
rescue AdsCommon::Errors::HttpError => e
|
66
|
+
puts "HTTP Error: %s" % e
|
67
|
+
|
68
|
+
# API errors.
|
69
|
+
rescue AdwordsApi::Errors::ApiException => e
|
70
|
+
puts "Message: %s" % e.message
|
71
|
+
puts 'Errors:'
|
72
|
+
e.errors.each_with_index do |error, index|
|
73
|
+
puts "\tError [%d]:" % (index + 1)
|
74
|
+
error.each do |field, value|
|
75
|
+
puts "\t\t%s: %s" % [field, value]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|