google-adwords-api 0.15.1 → 0.15.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/ChangeLog +4 -0
- data/examples/v201502/extensions/add_google_my_business_location_extensions.rb +4 -4
- data/examples/v201506/account_management/create_account.rb +92 -0
- data/examples/v201506/account_management/get_account_changes.rb +143 -0
- data/examples/v201506/account_management/get_account_hierarchy.rb +98 -0
- data/examples/v201506/advanced_operations/add_ad_customizers.rb +189 -0
- data/examples/v201506/advanced_operations/add_ad_group_bid_modifier.rb +105 -0
- data/examples/v201506/advanced_operations/add_click_to_download_ad.rb +137 -0
- data/examples/v201506/advanced_operations/add_text_ad_with_upgraded_urls.rb +138 -0
- data/examples/v201506/advanced_operations/create_and_attach_shared_keyword_set.rb +137 -0
- data/examples/v201506/advanced_operations/find_and_remove_criteria_from_shared_set.rb +171 -0
- data/examples/v201506/advanced_operations/get_ad_group_bid_modifiers.rb +106 -0
- data/examples/v201506/advanced_operations/upload_offline_conversions.rb +117 -0
- data/examples/v201506/advanced_operations/use_shared_bidding_strategy.rb +152 -0
- data/examples/v201506/basic_operations/add_ad_groups.rb +144 -0
- data/examples/v201506/basic_operations/add_campaigns.rb +143 -0
- data/examples/v201506/basic_operations/add_keywords.rb +118 -0
- data/examples/v201506/basic_operations/add_text_ads.rb +113 -0
- data/examples/v201506/basic_operations/get_ad_groups.rb +106 -0
- data/examples/v201506/basic_operations/get_campaigns.rb +101 -0
- data/examples/v201506/basic_operations/get_campaigns_with_awql.rb +93 -0
- data/examples/v201506/basic_operations/get_keywords.rb +112 -0
- data/examples/v201506/basic_operations/get_text_ads.rb +114 -0
- data/examples/v201506/basic_operations/pause_ad.rb +92 -0
- data/examples/v201506/basic_operations/remove_ad.rb +93 -0
- data/examples/v201506/basic_operations/remove_ad_group.rb +89 -0
- data/examples/v201506/basic_operations/remove_campaign.rb +91 -0
- data/examples/v201506/basic_operations/remove_keyword.rb +98 -0
- data/examples/v201506/basic_operations/update_ad_group.rb +89 -0
- data/examples/v201506/basic_operations/update_campaign.rb +90 -0
- data/examples/v201506/basic_operations/update_keyword.rb +110 -0
- data/examples/v201506/campaign_management/add_campaign_labels.rb +86 -0
- data/examples/v201506/campaign_management/add_experiment.rb +166 -0
- data/examples/v201506/campaign_management/add_keywords_in_bulk.rb +158 -0
- data/examples/v201506/campaign_management/get_all_disapproved_ads.rb +101 -0
- data/examples/v201506/campaign_management/get_all_disapproved_ads_with_awql.rb +93 -0
- data/examples/v201506/campaign_management/get_campaigns_by_label.rb +112 -0
- data/examples/v201506/campaign_management/promote_experiment.rb +85 -0
- data/examples/v201506/campaign_management/set_ad_parameters.rb +122 -0
- data/examples/v201506/campaign_management/set_criterion_bid_modifier.rb +108 -0
- data/examples/v201506/campaign_management/validate_text_ad.rb +114 -0
- data/examples/v201506/error_handling/handle_partial_failures.rb +134 -0
- data/examples/v201506/error_handling/handle_policy_violation_error.rb +145 -0
- data/examples/v201506/extensions/add_google_my_business_location_extensions.rb +190 -0
- data/examples/v201506/extensions/add_site_links.rb +168 -0
- data/examples/v201506/extensions/add_site_links_using_feeds.rb +276 -0
- data/examples/v201506/migration/migrate_to_extension_settings.rb +392 -0
- data/examples/v201506/migration/upgrade_ad_url.rb +97 -0
- data/examples/v201506/misc/create_ad_words_session_without_properties_file.rb +94 -0
- data/examples/v201506/misc/get_all_images_and_videos.rb +108 -0
- data/examples/v201506/misc/setup_oauth2.rb +88 -0
- data/examples/v201506/misc/upload_image.rb +97 -0
- data/examples/v201506/misc/use_oauth2_jwt.rb +97 -0
- data/examples/v201506/optimization/estimate_keyword_traffic.rb +150 -0
- data/examples/v201506/optimization/get_keyword_bid_simulations.rb +99 -0
- data/examples/v201506/optimization/get_keyword_ideas.rb +130 -0
- data/examples/v201506/remarketing/add_audience.rb +122 -0
- data/examples/v201506/remarketing/add_conversion_tracker.rb +104 -0
- data/examples/v201506/remarketing/add_rule_based_user_lists.rb +171 -0
- data/examples/v201506/reporting/download_criteria_report.rb +94 -0
- data/examples/v201506/reporting/download_criteria_report_with_awql.rb +95 -0
- data/examples/v201506/reporting/get_report_fields.rb +79 -0
- data/examples/v201506/reporting/parallel_report_download.rb +168 -0
- data/examples/v201506/shopping_campaigns/add_product_partition_tree.rb +269 -0
- data/examples/v201506/shopping_campaigns/add_product_scope.rb +133 -0
- data/examples/v201506/shopping_campaigns/add_shopping_campaign.rb +133 -0
- data/examples/v201506/shopping_campaigns/get_product_category_taxonomy.rb +117 -0
- data/examples/v201506/targeting/add_campaign_targeting_criteria.rb +184 -0
- data/examples/v201506/targeting/add_demographic_targeting_criteria.rb +116 -0
- data/examples/v201506/targeting/get_campaign_targeting_criteria.rb +110 -0
- data/examples/v201506/targeting/get_targetable_languages_and_carriers.rb +94 -0
- data/examples/v201506/targeting/lookup_location.rb +112 -0
- data/lib/adwords_api.rb +9 -0
- data/lib/adwords_api/api_config.rb +90 -4
- data/lib/adwords_api/report_header_handler.rb +5 -0
- data/lib/adwords_api/v201506/account_label_service.rb +38 -0
- data/lib/adwords_api/v201506/account_label_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_customizer_feed_service.rb +38 -0
- data/lib/adwords_api/v201506/ad_customizer_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_ad_service.rb +50 -0
- data/lib/adwords_api/v201506/ad_group_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_bid_modifier_service.rb +42 -0
- data/lib/adwords_api/v201506/ad_group_bid_modifier_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_criterion_service.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_extension_setting_service.rb +42 -0
- data/lib/adwords_api/v201506/ad_group_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_feed_service.rb +42 -0
- data/lib/adwords_api/v201506/ad_group_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_service.rb +46 -0
- data/lib/adwords_api/v201506/ad_group_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/ad_param_service.rb +38 -0
- data/lib/adwords_api/v201506/ad_param_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/adwords_user_list_service.rb +38 -0
- data/lib/adwords_api/v201506/adwords_user_list_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/bidding_strategy_service.rb +42 -0
- data/lib/adwords_api/v201506/bidding_strategy_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/budget_order_service.rb +42 -0
- data/lib/adwords_api/v201506/budget_order_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/budget_service.rb +42 -0
- data/lib/adwords_api/v201506/budget_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/campaign_criterion_service.rb +42 -0
- data/lib/adwords_api/v201506/campaign_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/campaign_extension_setting_service.rb +42 -0
- data/lib/adwords_api/v201506/campaign_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/campaign_feed_service.rb +42 -0
- data/lib/adwords_api/v201506/campaign_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/campaign_service.rb +46 -0
- data/lib/adwords_api/v201506/campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/campaign_shared_set_service.rb +42 -0
- data/lib/adwords_api/v201506/campaign_shared_set_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/constant_data_service.rb +66 -0
- data/lib/adwords_api/v201506/constant_data_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/conversion_tracker_service.rb +42 -0
- data/lib/adwords_api/v201506/conversion_tracker_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/customer_extension_setting_service.rb +42 -0
- data/lib/adwords_api/v201506/customer_extension_setting_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/customer_feed_service.rb +42 -0
- data/lib/adwords_api/v201506/customer_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/customer_service.rb +38 -0
- data/lib/adwords_api/v201506/customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/customer_sync_service.rb +34 -0
- data/lib/adwords_api/v201506/customer_sync_service_registry.rb +47 -0
- data/lib/adwords_api/v201506/data_service.rb +54 -0
- data/lib/adwords_api/v201506/data_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/experiment_service.rb +38 -0
- data/lib/adwords_api/v201506/experiment_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/feed_item_service.rb +42 -0
- data/lib/adwords_api/v201506/feed_item_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/feed_mapping_service.rb +42 -0
- data/lib/adwords_api/v201506/feed_mapping_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/feed_service.rb +42 -0
- data/lib/adwords_api/v201506/feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/geo_location_service.rb +34 -0
- data/lib/adwords_api/v201506/geo_location_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/label_service.rb +42 -0
- data/lib/adwords_api/v201506/label_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/location_criterion_service.rb +38 -0
- data/lib/adwords_api/v201506/location_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/managed_customer_service.rb +54 -0
- data/lib/adwords_api/v201506/managed_customer_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/media_service.rb +42 -0
- data/lib/adwords_api/v201506/media_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/mutate_job_service.rb +42 -0
- data/lib/adwords_api/v201506/mutate_job_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/offline_conversion_feed_service.rb +34 -0
- data/lib/adwords_api/v201506/offline_conversion_feed_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/report_definition_service.rb +34 -0
- data/lib/adwords_api/v201506/report_definition_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/shared_criterion_service.rb +42 -0
- data/lib/adwords_api/v201506/shared_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/shared_set_service.rb +42 -0
- data/lib/adwords_api/v201506/shared_set_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/targeting_idea_service.rb +34 -0
- data/lib/adwords_api/v201506/targeting_idea_service_registry.rb +46 -0
- data/lib/adwords_api/v201506/traffic_estimator_service.rb +34 -0
- data/lib/adwords_api/v201506/traffic_estimator_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_adwords_api.rb +1 -1
- data/test/adwords_api/test_api_config.rb +8 -8
- data/test/adwords_api/test_choices.rb +2 -2
- data/test/adwords_api/test_report_utils.rb +1 -1
- data/test/templates/v201506/basic_operations_get_campaigns.def +116 -0
- data/test/templates/v201506/misc_use_oauth2_jwt.def +131 -0
- metadata +156 -2
@@ -0,0 +1,105 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2013, 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 an ad group level mobile bid modifier
|
22
|
+
# override for a campaign.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupBidModifierService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_ad_group_bid_modifier(ad_group_id, bid_modifier)
|
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
|
+
bid_modifier_srv = adwords.service(:AdGroupBidModifierService, API_VERSION)
|
38
|
+
|
39
|
+
# Mobile criterion ID.
|
40
|
+
criterion_id = 30001
|
41
|
+
|
42
|
+
# Prepare to add an ad group level override.
|
43
|
+
operation = {
|
44
|
+
# Use 'ADD' to add a new modifier and 'SET' to update an existing one. A
|
45
|
+
# modifier can be removed with the 'REMOVE' operator.
|
46
|
+
:operator => 'ADD',
|
47
|
+
:operand => {
|
48
|
+
:ad_group_id => ad_group_id,
|
49
|
+
:criterion => {
|
50
|
+
:xsi_type => 'Platform',
|
51
|
+
:id => criterion_id
|
52
|
+
},
|
53
|
+
:bid_modifier => bid_modifier
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
# Add ad group level mobile bid modifier.
|
58
|
+
response = bid_modifier_srv.mutate([operation])
|
59
|
+
if response and response[:value]
|
60
|
+
modifier = response[:value].first
|
61
|
+
value = modifier[:bid_modifier] || 'unset'
|
62
|
+
puts ('Campaign ID %d, AdGroup ID %d, Criterion ID %d was updated with ' +
|
63
|
+
'ad group level modifier: %s') %
|
64
|
+
[modifier[:campaign_id], modifier[:ad_group_id],
|
65
|
+
modifier[:criterion][:id], value]
|
66
|
+
else
|
67
|
+
puts 'No modifiers were added.'
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if __FILE__ == $0
|
72
|
+
API_VERSION = :v201506
|
73
|
+
|
74
|
+
begin
|
75
|
+
# ID of an ad group to add an override for.
|
76
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
77
|
+
# Bid modifier to override with.
|
78
|
+
bid_modifier = 1.5
|
79
|
+
|
80
|
+
add_ad_group_bid_modifier(ad_group_id, bid_modifier)
|
81
|
+
|
82
|
+
# Authorization error.
|
83
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
84
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
85
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
86
|
+
"to retrieve and store OAuth2 tokens."
|
87
|
+
puts "See this wiki page for more details:\n\n " +
|
88
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
89
|
+
|
90
|
+
# HTTP errors.
|
91
|
+
rescue AdsCommon::Errors::HttpError => e
|
92
|
+
puts "HTTP Error: %s" % e
|
93
|
+
|
94
|
+
# API errors.
|
95
|
+
rescue AdwordsApi::Errors::ApiException => e
|
96
|
+
puts "Message: %s" % e.message
|
97
|
+
puts 'Errors:'
|
98
|
+
e.errors.each_with_index do |error, index|
|
99
|
+
puts "\tError [%d]:" % (index + 1)
|
100
|
+
error.each do |field, value|
|
101
|
+
puts "\t\t%s: %s" % [field, value]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -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 2013, 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 code example creates a click-to-download ad, also known as an app
|
22
|
+
# promotion ad to a given ad group. To list ad groups, run get_ad_groups.rb.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupAdService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_click_to_download_ad(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_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
|
38
|
+
|
39
|
+
# Create the template elements for the ad. You can refer to
|
40
|
+
# https://developers.google.com/adwords/api/docs/appendix/templateads
|
41
|
+
# for the list of available template fields.
|
42
|
+
ad_data = {
|
43
|
+
:unique_name => 'adData',
|
44
|
+
:fields => [
|
45
|
+
{
|
46
|
+
:name => 'headline',
|
47
|
+
:field_text => 'Enjoy your drive in Mars',
|
48
|
+
:type => 'TEXT'
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:name => 'description1',
|
52
|
+
:field_text => 'Realistic physics simulation',
|
53
|
+
:type => 'TEXT'
|
54
|
+
},
|
55
|
+
{
|
56
|
+
:name => 'description2',
|
57
|
+
:field_text => 'Race against players online',
|
58
|
+
:type => 'TEXT'
|
59
|
+
},
|
60
|
+
{
|
61
|
+
:name => 'appId',
|
62
|
+
:field_text => 'com.example.demogame',
|
63
|
+
:type => 'TEXT'
|
64
|
+
},
|
65
|
+
{
|
66
|
+
:name => 'appStore',
|
67
|
+
:field_text => '2',
|
68
|
+
:type => 'ENUM'
|
69
|
+
}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
|
73
|
+
# Create click to download ad.
|
74
|
+
click_to_download_app_ad = {
|
75
|
+
:xsi_type => 'TemplateAd',
|
76
|
+
:name => 'Ad for demo game',
|
77
|
+
:template_id => 353,
|
78
|
+
:final_urls =>
|
79
|
+
['http://play.google.com/store/apps/details?id=com.example.demogame'],
|
80
|
+
:display_url => 'play.google.com',
|
81
|
+
:template_elements => [ad_data]
|
82
|
+
}
|
83
|
+
|
84
|
+
# Create ad group ad.
|
85
|
+
ad_group_ad = {
|
86
|
+
:ad_group_id => ad_group_id,
|
87
|
+
:ad => click_to_download_app_ad,
|
88
|
+
# Optional.
|
89
|
+
:status => 'PAUSED'
|
90
|
+
}
|
91
|
+
|
92
|
+
# Add ad.
|
93
|
+
response = ad_group_ad_srv.mutate([
|
94
|
+
{:operator => 'ADD', :operand => ad_group_ad}
|
95
|
+
])
|
96
|
+
if response and response[:value]
|
97
|
+
response[:value].each do |ad|
|
98
|
+
puts "Added new click-to-download ad to ad group ID %d with url '%s'." %
|
99
|
+
[ad[:ad][:id], ad[:ad][:final_urls[0]]]
|
100
|
+
end
|
101
|
+
else
|
102
|
+
raise StandardError, 'No ads were added.'
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
if __FILE__ == $0
|
107
|
+
API_VERSION = :v201506
|
108
|
+
|
109
|
+
begin
|
110
|
+
# Ad group ID to add text ads to.
|
111
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
112
|
+
add_click_to_download_ad(ad_group_id)
|
113
|
+
|
114
|
+
# Authorization error.
|
115
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
116
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
117
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
118
|
+
"to retrieve and store OAuth2 tokens."
|
119
|
+
puts "See this wiki page for more details:\n\n " +
|
120
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
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,138 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.mcloonan@gmail.com (Michael Cloonan)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 2014, 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 code example adds a text ad that uses advanced features of upgraded
|
22
|
+
# URLs.
|
23
|
+
#
|
24
|
+
# Tags: AdGroupAdService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
|
28
|
+
def add_text_ad_with_upgraded_urls(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_ad_srv = adwords.service(:AdGroupAdService, API_VERSION)
|
38
|
+
|
39
|
+
# Since your tracking URL will have two custom parameters, provide their
|
40
|
+
# values too. This can be provided at campaign, ad group, ad, criterion, or
|
41
|
+
# feed item levels.
|
42
|
+
season_parameter = {
|
43
|
+
:key => 'season',
|
44
|
+
:value => 'christmas'
|
45
|
+
}
|
46
|
+
|
47
|
+
promo_code_parameter = {
|
48
|
+
:key => 'promocode',
|
49
|
+
:value => 'NYC123'
|
50
|
+
}
|
51
|
+
|
52
|
+
tracking_url_parameters = {
|
53
|
+
:parameters => [season_parameter, promo_code_parameter]
|
54
|
+
}
|
55
|
+
|
56
|
+
text_ad = {
|
57
|
+
:xsi_type => 'TextAd',
|
58
|
+
:headline => 'Luxury Cruise to Mars',
|
59
|
+
:description1 => 'Visit the Red Planet in style.',
|
60
|
+
:description2 => 'Low-gravity fun for everyone!',
|
61
|
+
:display_url => 'www.example.com',
|
62
|
+
# Specify a tracking URL for 3rd party tracking provider. You may specify
|
63
|
+
# one at customer, campaign, ad group, ad, criterion, or feed item levels.
|
64
|
+
:tracking_url_template => 'http://tracker.example.com/' +
|
65
|
+
'?season={_season}&promocode={_promocode}&u={lpurl}',
|
66
|
+
:url_custom_parameters => tracking_url_parameters,
|
67
|
+
# Specify a list of final URLs. This field cannot be set if :url field
|
68
|
+
# is set. This may be specified at ad, criterion, and feed item levels.
|
69
|
+
:final_urls => [
|
70
|
+
'http://www.example.com/cruise/space/',
|
71
|
+
'http://www.example.com/locations/mars/'
|
72
|
+
],
|
73
|
+
# Specify a list of final mobile URLs. This field cannot be set if :url
|
74
|
+
# field is set. This may be specificed at ad, criterion, and
|
75
|
+
# feed item levels.
|
76
|
+
:final_mobile_urls => [
|
77
|
+
'http://mobile.example.com/cruise/space/',
|
78
|
+
'http://mobile.example.com/locations/mars/'
|
79
|
+
]
|
80
|
+
}
|
81
|
+
|
82
|
+
operation = {
|
83
|
+
:operator => 'ADD',
|
84
|
+
:operand => {:ad_group_id => ad_group_id, :ad => text_ad}
|
85
|
+
}
|
86
|
+
|
87
|
+
# Add ads.
|
88
|
+
response = ad_group_ad_srv.mutate([operation])
|
89
|
+
if response and response[:value]
|
90
|
+
response[:value].each do |ad|
|
91
|
+
text_ad = ad[:ad]
|
92
|
+
puts "Ad with ID %d and displayUrl '%s' was added." %
|
93
|
+
[text_ad[:id], text_ad[:display_url]]
|
94
|
+
puts "\tFinal URLs: %s" % [text_ad[:final_urls].join(', ')]
|
95
|
+
puts "\tFinal Mobile URLs: %s" % [text_ad[:final_mobile_urls].join(', ')]
|
96
|
+
puts "\tTracking URL template: %s" % [text_ad[:tracking_url_template]]
|
97
|
+
custom_parameters =
|
98
|
+
text_ad[:url_custom_parameters][:parameters].map do |custom_parameter|
|
99
|
+
"%s=%s" % [custom_parameter[:key], custom_parameter[:value]]
|
100
|
+
end
|
101
|
+
puts "\tCustom parameters: %s" % [custom_parameters.join(', ')]
|
102
|
+
end
|
103
|
+
else
|
104
|
+
raise StandardError, 'No ads were added.'
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
if __FILE__ == $0
|
109
|
+
API_VERSION = :v201506
|
110
|
+
|
111
|
+
begin
|
112
|
+
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
113
|
+
add_text_ad_with_upgraded_urls(ad_group_id)
|
114
|
+
|
115
|
+
# Authorization error.
|
116
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
117
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
118
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
119
|
+
"to retrieve and store OAuth2 tokens."
|
120
|
+
puts "See this wiki page for more details:\n\n " +
|
121
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
122
|
+
|
123
|
+
# HTTP errors.
|
124
|
+
rescue AdsCommon::Errors::HttpError => e
|
125
|
+
puts "HTTP Error: %s" % e
|
126
|
+
|
127
|
+
# API errors.
|
128
|
+
rescue AdwordsApi::Errors::ApiException => e
|
129
|
+
puts "Message: %s" % e.message
|
130
|
+
puts 'Errors:'
|
131
|
+
e.errors.each_with_index do |error, index|
|
132
|
+
puts "\tError [%d]:" % (index + 1)
|
133
|
+
error.each do |field, value|
|
134
|
+
puts "\t\t%s: %s" % [field, value]
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
@@ -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 2015, 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 creates a shared list of negative broad match keywords, it then
|
22
|
+
# attaches them to a campaign.
|
23
|
+
#
|
24
|
+
# Tags: SharedSetService.mutate, CampaignSharedSetService.mutate
|
25
|
+
|
26
|
+
require 'adwords_api'
|
27
|
+
require 'date'
|
28
|
+
|
29
|
+
def create_and_attach_shared_keyword_set(campaign_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
|
+
shared_set_srv = adwords.service(:SharedSetService, API_VERSION)
|
39
|
+
shared_criterion_srv = adwords.service(:SharedCriterionService, API_VERSION)
|
40
|
+
campaign_shared_set_srv =
|
41
|
+
adwords.service(:CampaignSharedSetService, API_VERSION)
|
42
|
+
|
43
|
+
# Keywords to create a shared set of.
|
44
|
+
keywords = ['mars cruise', 'mars hotels']
|
45
|
+
|
46
|
+
# Create shared negative keyword set.
|
47
|
+
shared_set = {
|
48
|
+
:name => 'API Negative keyword list - %d' % (Time.new.to_f * 1000).to_i,
|
49
|
+
:type => 'NEGATIVE_KEYWORDS'
|
50
|
+
}
|
51
|
+
|
52
|
+
# Add shared set.
|
53
|
+
response = shared_set_srv.mutate([
|
54
|
+
{:operator => 'ADD', :operand => shared_set}
|
55
|
+
])
|
56
|
+
|
57
|
+
if response and response[:value]
|
58
|
+
shared_set = response[:value].first
|
59
|
+
shared_set_id = shared_set[:shared_set_id]
|
60
|
+
puts "Shared set with ID %d and name '%s' was successfully added." %
|
61
|
+
[shared_set_id, shared_set[:name]]
|
62
|
+
else
|
63
|
+
raise StandardError, 'No shared set was added'
|
64
|
+
end
|
65
|
+
|
66
|
+
# Add negative keywords to shared set.
|
67
|
+
shared_criteria = keywords.map do |keyword|
|
68
|
+
{
|
69
|
+
:criterion => {
|
70
|
+
:xsi_type => 'Keyword',
|
71
|
+
:text => keyword,
|
72
|
+
:match_type => 'BROAD'
|
73
|
+
},
|
74
|
+
:negative => true,
|
75
|
+
:shared_set_id => shared_set_id
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
operations = shared_criteria.map do |criterion|
|
80
|
+
{:operator => 'ADD', :operand => criterion}
|
81
|
+
end
|
82
|
+
|
83
|
+
response = shared_criterion_srv.mutate(operations)
|
84
|
+
if response and response[:value]
|
85
|
+
response[:value].each do |shared_criterion|
|
86
|
+
puts "Added shared criterion ID %d '%s' to shared set with ID %d." %
|
87
|
+
[shared_criterion[:criterion][:id],
|
88
|
+
shared_criterion[:criterion][:text],
|
89
|
+
shared_criterion[:shared_set_id]]
|
90
|
+
end
|
91
|
+
else
|
92
|
+
raise StandardError, 'No shared keyword was added'
|
93
|
+
end
|
94
|
+
|
95
|
+
# Attach the articles to the campaign.
|
96
|
+
campaign_set = {
|
97
|
+
:campaign_id => campaign_id,
|
98
|
+
:shared_set_id => shared_set_id
|
99
|
+
}
|
100
|
+
|
101
|
+
response = campaign_shared_set_srv.mutate([
|
102
|
+
{:operator => 'ADD', :operand => campaign_set}
|
103
|
+
])
|
104
|
+
if response and response[:value]
|
105
|
+
campaign_shared_set = response[:value].first
|
106
|
+
puts 'Shared set ID %d was attached to campaign ID %d' %
|
107
|
+
[campaign_shared_set[:shared_set_id], campaign_shared_set[:campaign_id]]
|
108
|
+
else
|
109
|
+
raise StandardError, 'No campaign shared set was added'
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
if __FILE__ == $0
|
114
|
+
API_VERSION = :v201506
|
115
|
+
|
116
|
+
begin
|
117
|
+
# Campaign ID to attach shared keyword set to.
|
118
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
119
|
+
|
120
|
+
create_and_attach_shared_keyword_set(campaign_id)
|
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
|