google-adwords-api 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3 -0
- data/README +3 -3
- data/examples/v201206/basic_operations/add_campaigns.rb +7 -2
- data/examples/v201209/account_management/create_account.rb +84 -0
- data/examples/v201209/account_management/get_account_alerts.rb +111 -0
- data/examples/v201209/account_management/get_account_changes.rb +137 -0
- data/examples/v201209/account_management/get_account_hierarchy.rb +92 -0
- data/examples/v201209/account_management/get_client_customer_id.rb +85 -0
- data/examples/v201209/account_management/get_client_unit_usage.rb +87 -0
- data/examples/v201209/basic_operations/add_ad_groups.rb +136 -0
- data/examples/v201209/basic_operations/add_campaigns.rb +159 -0
- data/examples/v201209/basic_operations/add_keywords.rb +108 -0
- data/examples/v201209/basic_operations/add_text_ads.rb +105 -0
- data/examples/v201209/basic_operations/delete_ad.rb +85 -0
- data/examples/v201209/basic_operations/delete_ad_group.rb +102 -0
- data/examples/v201209/basic_operations/delete_campaign.rb +103 -0
- data/examples/v201209/basic_operations/delete_keyword.rb +90 -0
- data/examples/v201209/basic_operations/get_ad_groups.rb +98 -0
- data/examples/v201209/basic_operations/get_campaigns.rb +93 -0
- data/examples/v201209/basic_operations/get_campaigns_with_awql.rb +85 -0
- data/examples/v201209/basic_operations/get_keywords.rb +104 -0
- data/examples/v201209/basic_operations/get_text_ads.rb +106 -0
- data/examples/v201209/basic_operations/pause_ad.rb +84 -0
- data/examples/v201209/basic_operations/update_ad_group.rb +81 -0
- data/examples/v201209/basic_operations/update_campaign.rb +82 -0
- data/examples/v201209/basic_operations/update_keyword.rb +99 -0
- data/examples/v201209/campaign_management/add_experiment.rb +158 -0
- data/examples/v201209/campaign_management/add_keywords_in_bulk.rb +150 -0
- data/examples/v201209/campaign_management/add_location_extension.rb +117 -0
- data/examples/v201209/campaign_management/add_location_extension_override.rb +83 -0
- data/examples/v201209/campaign_management/get_all_disapproved_ads.rb +93 -0
- data/examples/v201209/campaign_management/get_all_disapproved_ads_with_awql.rb +84 -0
- data/examples/v201209/campaign_management/promote_experiment.rb +77 -0
- data/examples/v201209/campaign_management/set_ad_parameters.rb +114 -0
- data/examples/v201209/campaign_management/validate_text_ad.rb +106 -0
- data/examples/v201209/error_handling/handle_captcha_challenge.rb +93 -0
- data/examples/v201209/error_handling/handle_partial_failures.rb +126 -0
- data/examples/v201209/error_handling/handle_policy_violation_error.rb +137 -0
- data/examples/v201209/error_handling/handle_two_factor_authorization_error.rb +87 -0
- data/examples/v201209/misc/get_all_images_and_videos.rb +100 -0
- data/examples/v201209/misc/upload_image.rb +89 -0
- data/examples/v201209/misc/use_oauth.rb +100 -0
- data/examples/v201209/misc/use_oauth2.rb +97 -0
- data/examples/v201209/optimization/estimate_keyword_traffic.rb +129 -0
- data/examples/v201209/optimization/get_keyword_bid_simulations.rb +92 -0
- data/examples/v201209/optimization/get_keyword_ideas.rb +114 -0
- data/examples/v201209/optimization/get_placement_ideas.rb +104 -0
- data/examples/v201209/remarketing/add_audience.rb +115 -0
- data/examples/v201209/remarketing/add_conversion_tracker.rb +97 -0
- data/examples/v201209/reporting/download_criteria_report.rb +79 -0
- data/examples/v201209/reporting/download_criteria_report_with_awql.rb +78 -0
- data/examples/v201209/reporting/get_campaign_stats.rb +105 -0
- data/examples/v201209/reporting/get_report_fields.rb +71 -0
- data/examples/v201209/reporting/parallel_report_download.rb +160 -0
- data/examples/v201209/targeting/add_campaign_targeting_criteria.rb +118 -0
- data/examples/v201209/targeting/add_demographic_targeting_criteria.rb +108 -0
- data/examples/v201209/targeting/get_campaign_targeting_criteria.rb +102 -0
- data/examples/v201209/targeting/get_targetable_languages_and_carriers.rb +86 -0
- data/examples/v201209/targeting/lookup_location.rb +104 -0
- data/lib/adwords_api/api_config.rb +64 -5
- data/lib/adwords_api/errors.rb +15 -0
- data/lib/adwords_api/report_utils.rb +30 -11
- data/lib/adwords_api/v201209/ad_extension_override_service.rb +38 -0
- data/lib/adwords_api/v201209/ad_extension_override_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/ad_group_ad_service.rb +42 -0
- data/lib/adwords_api/v201209/ad_group_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/ad_group_criterion_service.rb +42 -0
- data/lib/adwords_api/v201209/ad_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/ad_group_service.rb +42 -0
- data/lib/adwords_api/v201209/ad_group_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/ad_param_service.rb +38 -0
- data/lib/adwords_api/v201209/ad_param_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/alert_service.rb +34 -0
- data/lib/adwords_api/v201209/alert_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/budget_order_service.rb +42 -0
- data/lib/adwords_api/v201209/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/budget_service.rb +38 -0
- data/lib/adwords_api/v201209/budget_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/campaign_ad_extension_service.rb +38 -0
- data/lib/adwords_api/v201209/campaign_ad_extension_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/campaign_criterion_service.rb +42 -0
- data/lib/adwords_api/v201209/campaign_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/campaign_service.rb +42 -0
- data/lib/adwords_api/v201209/campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/constant_data_service.rb +62 -0
- data/lib/adwords_api/v201209/constant_data_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/conversion_tracker_service.rb +38 -0
- data/lib/adwords_api/v201209/conversion_tracker_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/customer_service.rb +34 -0
- data/lib/adwords_api/v201209/customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/customer_sync_service.rb +34 -0
- data/lib/adwords_api/v201209/customer_sync_service_registry.rb +47 -0
- data/lib/adwords_api/v201209/data_service.rb +38 -0
- data/lib/adwords_api/v201209/data_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/experiment_service.rb +38 -0
- data/lib/adwords_api/v201209/experiment_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/geo_location_service.rb +34 -0
- data/lib/adwords_api/v201209/geo_location_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/info_service.rb +34 -0
- data/lib/adwords_api/v201209/info_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/location_criterion_service.rb +34 -0
- data/lib/adwords_api/v201209/location_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/managed_customer_service.rb +38 -0
- data/lib/adwords_api/v201209/managed_customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/media_service.rb +38 -0
- data/lib/adwords_api/v201209/media_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/mutate_job_service.rb +42 -0
- data/lib/adwords_api/v201209/mutate_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/report_definition_service.rb +34 -0
- data/lib/adwords_api/v201209/report_definition_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/targeting_idea_service.rb +38 -0
- data/lib/adwords_api/v201209/targeting_idea_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/traffic_estimator_service.rb +34 -0
- data/lib/adwords_api/v201209/traffic_estimator_service_registry.rb +46 -0
- data/lib/adwords_api/v201209/user_list_service.rb +38 -0
- data/lib/adwords_api/v201209/user_list_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_report_utils.rb +94 -6
- data/test/examples/v201209/test_account_management.rb +60 -0
- data/test/examples/v201209/test_basic_operations.rb +177 -0
- data/test/examples/v201209/test_campaign_management.rb +124 -0
- data/test/examples/v201209/test_error_handling.rb +63 -0
- data/test/examples/v201209/test_misc.rb +45 -0
- data/test/examples/v201209/test_optimization.rb +63 -0
- data/test/examples/v201209/test_remarketing.rb +39 -0
- data/test/examples/v201209/test_reporting.rb +84 -0
- data/test/examples/v201209/test_targeting.rb +60 -0
- data/test/examples/v201209/utils.rb +238 -0
- data/test/suite_exampletests_v201209.rb +37 -0
- metadata +123 -2
@@ -0,0 +1,108 @@
|
|
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 adds demographic criteria to an ad group. To get ad groups list,
|
22
|
+
# run get_ad_groups.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupCriterionService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_demographic_targeting_criteria(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 ad group criteria.
|
41
|
+
ad_group_criteria = [
|
42
|
+
# Targeting criterion.
|
43
|
+
{
|
44
|
+
:xsi_type => 'BiddableAdGroupCriterion',
|
45
|
+
:ad_group_id => ad_group_id,
|
46
|
+
:criterion => {
|
47
|
+
:xsi_type => 'Gender',
|
48
|
+
# See system codes section for IDs:
|
49
|
+
# https://developers.google.com/adwords/api/docs/appendix/genders
|
50
|
+
:id => 11
|
51
|
+
}
|
52
|
+
},
|
53
|
+
# Exclusion criterion.
|
54
|
+
{
|
55
|
+
:xsi_type => 'NegativeAdGroupCriterion',
|
56
|
+
:ad_group_id => ad_group_id,
|
57
|
+
:criterion => {
|
58
|
+
:xsi_type => 'AgeRange',
|
59
|
+
# See system codes section for IDs:
|
60
|
+
# https://developers.google.com/adwords/api/docs/appendix/ages
|
61
|
+
:id => 503999
|
62
|
+
}
|
63
|
+
}
|
64
|
+
]
|
65
|
+
|
66
|
+
# Create operations.
|
67
|
+
operations = ad_group_criteria.map do |criterion|
|
68
|
+
{:operator => 'ADD', :operand => criterion}
|
69
|
+
end
|
70
|
+
|
71
|
+
response = ad_group_criterion_srv.mutate(operations)
|
72
|
+
|
73
|
+
if response and response[:value]
|
74
|
+
criteria = response[:value]
|
75
|
+
criteria.each do |ad_group_criterion|
|
76
|
+
criterion = ad_group_criterion[:criterion]
|
77
|
+
puts ("Ad group criterion with ad group ID %d, criterion ID %d and " +
|
78
|
+
"type '%s' was added.") % [ad_group_criterion[:ad_group_id],
|
79
|
+
criterion[:id], criterion[:criterion_type]]
|
80
|
+
end
|
81
|
+
else
|
82
|
+
puts 'No criteria were returned.'
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
if __FILE__ == $0
|
87
|
+
API_VERSION = :v201209
|
88
|
+
|
89
|
+
begin
|
90
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'
|
91
|
+
add_demographic_targeting_criteria(ad_group_id)
|
92
|
+
|
93
|
+
# HTTP errors.
|
94
|
+
rescue AdsCommon::Errors::HttpError => e
|
95
|
+
puts "HTTP Error: %s" % e
|
96
|
+
|
97
|
+
# API errors.
|
98
|
+
rescue AdwordsApi::Errors::ApiException => e
|
99
|
+
puts "Message: %s" % e.message
|
100
|
+
puts 'Errors:'
|
101
|
+
e.errors.each_with_index do |error, index|
|
102
|
+
puts "\tError [%d]:" % (index + 1)
|
103
|
+
error.each do |field, value|
|
104
|
+
puts "\t\t%s: %s" % [field, value]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,102 @@
|
|
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 campaign targets. To set
|
22
|
+
# campaign targets, run add_campaign_targeting_criteria.rb.
|
23
|
+
#
|
24
|
+
# Tags: CampaignCriterionService.get
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def get_campaign_targeting_criteria(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_criterion_srv =
|
38
|
+
adwords.service(:CampaignCriterionService, API_VERSION)
|
39
|
+
|
40
|
+
# Selector to get all the targeting for this campaign.
|
41
|
+
selector = {
|
42
|
+
:fields => ['Id', 'CriteriaType', 'KeywordText'],
|
43
|
+
:predicates => [
|
44
|
+
{:field => 'CampaignId', :operator => 'EQUALS', :values => [campaign_id]}
|
45
|
+
],
|
46
|
+
:paging => {
|
47
|
+
:start_index => 0,
|
48
|
+
:number_results => PAGE_SIZE
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
# Set initial values.
|
53
|
+
offset, page = 0, {}
|
54
|
+
|
55
|
+
begin
|
56
|
+
page = campaign_criterion_srv.get(selector)
|
57
|
+
if page[:entries]
|
58
|
+
page[:entries].each do |typed_criterion|
|
59
|
+
negative = typed_criterion[:xsi_type] == 'NegativeCampaignCriterion' ?
|
60
|
+
' (negative)' : ''
|
61
|
+
criterion = typed_criterion[:criterion]
|
62
|
+
puts ("Campaign criterion%s with ID %d, type '%s' and text '%s'" +
|
63
|
+
" was found.") %
|
64
|
+
[negative, criterion[:id], criterion[:type], criterion[:text]]
|
65
|
+
end
|
66
|
+
# Increment values to request the next page.
|
67
|
+
offset += PAGE_SIZE
|
68
|
+
selector[:paging][:start_index] = offset
|
69
|
+
end
|
70
|
+
end while page[:total_num_entries] > offset
|
71
|
+
|
72
|
+
if page.include?(:total_num_entries)
|
73
|
+
puts "\tCampaign ID %d has %d criteria." %
|
74
|
+
[campaign_id, page[:total_num_entries]]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
if __FILE__ == $0
|
79
|
+
API_VERSION = :v201209
|
80
|
+
PAGE_SIZE = 500
|
81
|
+
|
82
|
+
begin
|
83
|
+
# Specify campaign ID to get targeting for.
|
84
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
85
|
+
get_campaign_targeting_criteria(campaign_id)
|
86
|
+
|
87
|
+
# HTTP errors.
|
88
|
+
rescue AdsCommon::Errors::HttpError => e
|
89
|
+
puts "HTTP Error: %s" % e
|
90
|
+
|
91
|
+
# API errors.
|
92
|
+
rescue AdwordsApi::Errors::ApiException => e
|
93
|
+
puts "Message: %s" % e.message
|
94
|
+
puts 'Errors:'
|
95
|
+
e.errors.each_with_index do |error, index|
|
96
|
+
puts "\tError [%d]:" % (index + 1)
|
97
|
+
error.each do |field, value|
|
98
|
+
puts "\t\t%s: %s" % [field, value]
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,86 @@
|
|
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 languages and carriers available
|
22
|
+
# for targeting.
|
23
|
+
#
|
24
|
+
# Tags: ConstantDataService.getLanguageCriterion
|
25
|
+
# Tags: ConstantDataService.getCarrierCriterion
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
def get_targetable_languages_and_carriers()
|
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
|
+
constant_data_srv = adwords.service(:ConstantDataService, API_VERSION)
|
39
|
+
|
40
|
+
# Get all languages from ConstantDataService.
|
41
|
+
languages = constant_data_srv.get_language_criterion()
|
42
|
+
|
43
|
+
if languages
|
44
|
+
languages.each do |language|
|
45
|
+
puts "Language name is '%s', ID is %d and code is '%s'." %
|
46
|
+
[language[:name], language[:id], language[:code]]
|
47
|
+
end
|
48
|
+
else
|
49
|
+
puts 'No languages were found.'
|
50
|
+
end
|
51
|
+
|
52
|
+
# Get all carriers from ConstantDataService.
|
53
|
+
carriers = constant_data_srv.get_carrier_criterion()
|
54
|
+
|
55
|
+
if carriers
|
56
|
+
carriers.each do |carrier|
|
57
|
+
puts "Carrier name is '%s', ID is %d and country code is '%s'." %
|
58
|
+
[carrier[:name], carrier[:id], carrier[:country_code]]
|
59
|
+
end
|
60
|
+
else
|
61
|
+
puts 'No carriers were retrieved.'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if __FILE__ == $0
|
66
|
+
API_VERSION = :v201209
|
67
|
+
|
68
|
+
begin
|
69
|
+
get_targetable_languages_and_carriers()
|
70
|
+
|
71
|
+
# HTTP errors.
|
72
|
+
rescue AdsCommon::Errors::HttpError => e
|
73
|
+
puts "HTTP Error: %s" % e
|
74
|
+
|
75
|
+
# API errors.
|
76
|
+
rescue AdwordsApi::Errors::ApiException => e
|
77
|
+
puts "Message: %s" % e.message
|
78
|
+
puts 'Errors:'
|
79
|
+
e.errors.each_with_index do |error, index|
|
80
|
+
puts "\tError [%d]:" % (index + 1)
|
81
|
+
error.each do |field, value|
|
82
|
+
puts "\t\t%s: %s" % [field, value]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,104 @@
|
|
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 location criteria by name.
|
22
|
+
#
|
23
|
+
# Tags: LocationCriterionService.get
|
24
|
+
|
25
|
+
require 'adwords_api'
|
26
|
+
|
27
|
+
def lookup_location()
|
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
|
+
location_criterion_srv =
|
37
|
+
adwords.service(:LocationCriterionService, API_VERSION)
|
38
|
+
|
39
|
+
# List of locations to look up.
|
40
|
+
location_names = ['Paris', 'Quebec', 'Spain', 'Deutschland']
|
41
|
+
# Locale to retrieve names in.
|
42
|
+
locale = 'en'
|
43
|
+
|
44
|
+
# Get the criteria by names.
|
45
|
+
selector = {
|
46
|
+
:fields => ['Id', 'LocationName', 'CanonicalName', 'DisplayType',
|
47
|
+
'ParentLocations', 'Reach', 'TargetingStatus'],
|
48
|
+
:predicates => [
|
49
|
+
# Location names must match exactly, only EQUALS and IN are supported.
|
50
|
+
{:field => 'LocationName',
|
51
|
+
:operator => 'IN',
|
52
|
+
:values => location_names},
|
53
|
+
# Set the locale of the returned location names.
|
54
|
+
{:field => 'Locale', :operator => 'EQUALS', :values => [locale]}
|
55
|
+
]
|
56
|
+
}
|
57
|
+
criteria = location_criterion_srv.get(selector)
|
58
|
+
|
59
|
+
if criteria
|
60
|
+
criteria.each do |criterion|
|
61
|
+
# Extract all parent location names as one comma-separated string.
|
62
|
+
parent_location = if criterion[:location][:parent_locations] and
|
63
|
+
!criterion[:location][:parent_locations].empty?
|
64
|
+
locations_array = criterion[:location][:parent_locations].map do |loc|
|
65
|
+
loc[:location_name]
|
66
|
+
end
|
67
|
+
locations_array.join(', ')
|
68
|
+
else
|
69
|
+
'N/A'
|
70
|
+
end
|
71
|
+
puts ("The search term '%s' returned the location '%s' of type '%s' " +
|
72
|
+
"with ID %d, parent locations '%s' and reach %d (%s)") %
|
73
|
+
[criterion[:search_term], criterion[:location][:location_name],
|
74
|
+
criterion[:location][:criterion_type], criterion[:location][:id],
|
75
|
+
parent_location, criterion[:reach],
|
76
|
+
criterion[:location][:targeting_status]]
|
77
|
+
end
|
78
|
+
else
|
79
|
+
puts 'No criteria were returned.'
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
if __FILE__ == $0
|
84
|
+
API_VERSION = :v201209
|
85
|
+
|
86
|
+
begin
|
87
|
+
lookup_location()
|
88
|
+
|
89
|
+
# HTTP errors.
|
90
|
+
rescue AdsCommon::Errors::HttpError => e
|
91
|
+
puts "HTTP Error: %s" % e
|
92
|
+
|
93
|
+
# API errors.
|
94
|
+
rescue AdwordsApi::Errors::ApiException => e
|
95
|
+
puts "Message: %s" % e.message
|
96
|
+
puts 'Errors:'
|
97
|
+
e.errors.each_with_index do |error, index|
|
98
|
+
puts "\tError [%d]:" % (index + 1)
|
99
|
+
error.each do |field, value|
|
100
|
+
puts "\t\t%s: %s" % [field, value]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -35,9 +35,9 @@ module AdwordsApi
|
|
35
35
|
end
|
36
36
|
|
37
37
|
# Set defaults
|
38
|
-
DEFAULT_VERSION = :
|
38
|
+
DEFAULT_VERSION = :v201209
|
39
39
|
DEFAULT_ENVIRONMENT = :PRODUCTION
|
40
|
-
LATEST_VERSION = :
|
40
|
+
LATEST_VERSION = :v201209
|
41
41
|
|
42
42
|
# Set other constants
|
43
43
|
API_NAME = 'AdwordsApi'
|
@@ -135,6 +135,35 @@ module AdwordsApi
|
|
135
135
|
:TargetingIdeaService,
|
136
136
|
:TrafficEstimatorService,
|
137
137
|
:UserListService
|
138
|
+
],
|
139
|
+
:v201209 => [
|
140
|
+
:AdExtensionOverrideService,
|
141
|
+
:AdGroupAdService,
|
142
|
+
:AdGroupCriterionService,
|
143
|
+
:AdGroupService,
|
144
|
+
:AdParamService,
|
145
|
+
:AlertService,
|
146
|
+
:BudgetOrderService,
|
147
|
+
:BudgetService,
|
148
|
+
:CampaignAdExtensionService,
|
149
|
+
:CampaignCriterionService,
|
150
|
+
:CampaignService,
|
151
|
+
:ConstantDataService,
|
152
|
+
:ConversionTrackerService,
|
153
|
+
:CustomerService,
|
154
|
+
:CustomerSyncService,
|
155
|
+
:DataService,
|
156
|
+
:ExperimentService,
|
157
|
+
:GeoLocationService,
|
158
|
+
:InfoService,
|
159
|
+
:LocationCriterionService,
|
160
|
+
:ManagedCustomerService,
|
161
|
+
:MediaService,
|
162
|
+
:MutateJobService,
|
163
|
+
:ReportDefinitionService,
|
164
|
+
:TargetingIdeaService,
|
165
|
+
:TrafficEstimatorService,
|
166
|
+
:UserListService
|
138
167
|
]
|
139
168
|
}
|
140
169
|
|
@@ -145,14 +174,16 @@ module AdwordsApi
|
|
145
174
|
:header_ns => 'https://adwords.google.com/api/adwords/cm/',
|
146
175
|
:v201109 => 'https://adwords.google.com/api/adwords/',
|
147
176
|
:v201109_1 => 'https://adwords.google.com/api/adwords/',
|
148
|
-
:v201206 => 'https://adwords.google.com/api/adwords/'
|
177
|
+
:v201206 => 'https://adwords.google.com/api/adwords/',
|
178
|
+
:v201209 => 'https://adwords.google.com/api/adwords/'
|
149
179
|
},
|
150
180
|
:SANDBOX => {
|
151
181
|
:oauth_scope => 'https://adwords-sandbox.google.com/api/adwords/',
|
152
182
|
:header_ns => 'https://adwords.google.com/api/adwords/cm/',
|
153
183
|
:v201109 => 'https://adwords-sandbox.google.com/api/adwords/',
|
154
184
|
:v201109_1 => 'https://adwords-sandbox.google.com/api/adwords/',
|
155
|
-
:v201206 => 'https://adwords-sandbox.google.com/api/adwords/'
|
185
|
+
:v201206 => 'https://adwords-sandbox.google.com/api/adwords/',
|
186
|
+
:v201209 => 'https://adwords-sandbox.google.com/api/adwords/'
|
156
187
|
}
|
157
188
|
}
|
158
189
|
|
@@ -246,7 +277,35 @@ module AdwordsApi
|
|
246
277
|
[:v201206, :TrafficEstimatorService] => 'o/',
|
247
278
|
[:v201206, :UserListService] => 'cm/',
|
248
279
|
[:v201206, :ManagedCustomerService] => 'mcm/',
|
249
|
-
[:v201206, :CustomerService] => 'mcm/'
|
280
|
+
[:v201206, :CustomerService] => 'mcm/',
|
281
|
+
# v201209
|
282
|
+
[:v201209, :AdExtensionOverrideService] => 'cm/',
|
283
|
+
[:v201209, :AdGroupAdService] => 'cm/',
|
284
|
+
[:v201209, :AdGroupCriterionService] => 'cm/',
|
285
|
+
[:v201209, :AdGroupService] => 'cm/',
|
286
|
+
[:v201209, :AdParamService] => 'cm/',
|
287
|
+
[:v201209, :AlertService] => 'mcm/',
|
288
|
+
[:v201209, :BudgetOrderService] => 'billing/',
|
289
|
+
[:v201209, :CampaignAdExtensionService] => 'cm/',
|
290
|
+
[:v201209, :CampaignCriterionService] => 'cm/',
|
291
|
+
[:v201209, :CampaignService] => 'cm/',
|
292
|
+
[:v201209, :ConstantDataService] => 'cm/',
|
293
|
+
[:v201209, :ConversionTrackerService] => 'cm/',
|
294
|
+
[:v201209, :CustomerSyncService] => 'ch/',
|
295
|
+
[:v201209, :DataService] => 'cm/',
|
296
|
+
[:v201209, :ExperimentService] => 'cm/',
|
297
|
+
[:v201209, :GeoLocationService] => 'cm/',
|
298
|
+
[:v201209, :InfoService] => 'info/',
|
299
|
+
[:v201209, :LocationCriterionService] => 'cm/',
|
300
|
+
[:v201209, :MediaService] => 'cm/',
|
301
|
+
[:v201209, :MutateJobService] => 'cm/',
|
302
|
+
[:v201209, :ReportDefinitionService] => 'cm/',
|
303
|
+
[:v201209, :TargetingIdeaService] => 'o/',
|
304
|
+
[:v201209, :TrafficEstimatorService] => 'o/',
|
305
|
+
[:v201209, :UserListService] => 'cm/',
|
306
|
+
[:v201209, :ManagedCustomerService] => 'mcm/',
|
307
|
+
[:v201209, :CustomerService] => 'mcm/',
|
308
|
+
[:v201209, :BudgetService] => 'cm/'
|
250
309
|
}
|
251
310
|
|
252
311
|
# Auth constants for ClientLogin method.
|