google-adx-buyer-api 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/ChangeLog +4 -0
  2. data/README +4 -4
  3. data/examples/v201302/account_management/get_account_changes.rb +137 -0
  4. data/examples/v201302/basic_operations/add_ad_group.rb +88 -0
  5. data/examples/v201302/basic_operations/add_campaign.rb +102 -0
  6. data/examples/v201302/basic_operations/add_placements.rb +99 -0
  7. data/examples/v201302/basic_operations/add_thirdparty_redirect_ad.rb +126 -0
  8. data/examples/v201302/basic_operations/delete_ad.rb +80 -0
  9. data/examples/v201302/basic_operations/delete_ad_group.rb +76 -0
  10. data/examples/v201302/basic_operations/delete_campaign.rb +77 -0
  11. data/examples/v201302/basic_operations/delete_placement.rb +86 -0
  12. data/examples/v201302/basic_operations/get_ad_groups.rb +80 -0
  13. data/examples/v201302/basic_operations/get_campaigns.rb +77 -0
  14. data/examples/v201302/basic_operations/get_placements.rb +92 -0
  15. data/examples/v201302/basic_operations/get_thirdparty_redirect_ads.rb +100 -0
  16. data/examples/v201302/basic_operations/pause_ad.rb +81 -0
  17. data/examples/v201302/basic_operations/update_ad_group.rb +76 -0
  18. data/examples/v201302/basic_operations/update_campaign.rb +79 -0
  19. data/examples/v201302/basic_operations/update_placement.rb +94 -0
  20. data/examples/v201302/campaign_management/add_placements_in_bulk.rb +151 -0
  21. data/examples/v201302/campaign_management/get_all_disapproved_ads.rb +92 -0
  22. data/examples/v201302/error_handling/handle_captcha_challenge.rb +93 -0
  23. data/examples/v201302/error_handling/handle_partial_failures.rb +117 -0
  24. data/examples/v201302/error_handling/handle_policy_violation_error.rb +138 -0
  25. data/examples/v201302/error_handling/handle_two_factor_authorization_error.rb +88 -0
  26. data/examples/v201302/misc/get_all_images_and_videos.rb +100 -0
  27. data/examples/v201302/misc/upload_image.rb +89 -0
  28. data/examples/v201302/misc/use_oauth2.rb +97 -0
  29. data/examples/v201302/misc/use_oauth2_jwt.rb +93 -0
  30. data/examples/v201302/optimization/get_placement_ideas.rb +104 -0
  31. data/examples/v201302/remarketing/add_audience.rb +115 -0
  32. data/examples/v201302/remarketing/add_conversion_tracker.rb +96 -0
  33. data/examples/v201302/reporting/download_criteria_report.rb +79 -0
  34. data/examples/v201302/reporting/get_campaign_stats.rb +105 -0
  35. data/examples/v201302/reporting/get_report_fields.rb +71 -0
  36. data/examples/v201302/targeting/add_campaign_targeting_criteria.rb +107 -0
  37. data/examples/v201302/targeting/get_campaign_targeting_criteria.rb +104 -0
  38. data/examples/v201302/targeting/get_targetable_languages_and_carriers.rb +86 -0
  39. data/examples/v201302/targeting/lookup_location.rb +104 -0
  40. metadata +41 -4
@@ -0,0 +1,79 @@
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 and downloads an Ad Hoc report from a XML report definition.
22
+
23
+ require 'adwords_api'
24
+
25
+ def download_criteria_report(file_name)
26
+ # AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
27
+ # when called without parameters.
28
+ adwords = AdwordsApi::Api.new
29
+
30
+ # To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
31
+ # the configuration file or provide your own logger:
32
+ # adwords.logger = Logger.new('adwords_xml.log')
33
+
34
+ # Get report utilities for the version.
35
+ report_utils = adwords.report_utils(API_VERSION)
36
+
37
+ # Define report definition. You can also pass your own XML text as a string.
38
+ report_definition = {
39
+ :selector => {
40
+ :fields => ['CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType',
41
+ 'Impressions', 'Clicks', 'Cost'],
42
+ # Predicates are optional.
43
+ :predicates => {
44
+ :field => 'Status',
45
+ :operator => 'IN',
46
+ :values => ['ACTIVE', 'PAUSED']
47
+ }
48
+ },
49
+ :report_name => 'Last 7 days CRITERIA_PERFORMANCE_REPORT',
50
+ :report_type => 'CRITERIA_PERFORMANCE_REPORT',
51
+ :download_format => 'CSV',
52
+ :date_range_type => 'LAST_7_DAYS',
53
+ # Enable to get rows with zero impressions.
54
+ :include_zero_impressions => false
55
+ }
56
+
57
+ # Download report, using "download_report_as_file" utility method.
58
+ # To retrieve the report as return value, use "download_report" method.
59
+ report_utils.download_report_as_file(report_definition, file_name)
60
+ puts "Report was downloaded to '%s'." % file_name
61
+ end
62
+
63
+ if __FILE__ == $0
64
+ API_VERSION = :v201302
65
+
66
+ begin
67
+ # File name to write report to.
68
+ file_name = 'INSERT_OUTPUT_FILE_NAME_HERE'
69
+ download_criteria_report(file_name)
70
+
71
+ # HTTP errors.
72
+ rescue AdsCommon::Errors::HttpError => e
73
+ puts "HTTP Error: %s" % e
74
+
75
+ # API errors.
76
+ rescue AdwordsApi::Errors::ReportError => e
77
+ puts "Reporting Error: %s" % e.message
78
+ end
79
+ end
@@ -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 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 gets various statistics for campaigns that received at least one
22
+ # impression during the last week. To get campaigns, run get_campaigns.rb.
23
+ #
24
+ # Tags: CampaignService.get
25
+
26
+ require 'adwords_api'
27
+ require 'date'
28
+
29
+ def get_campaign_stats()
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
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
39
+
40
+ # Prepare start and end date for the last week.
41
+ start_date = DateTime.parse((Date.today - 7).to_s).strftime("%Y%m%d")
42
+ end_date = DateTime.parse((Date.today - 1).to_s).strftime("%Y%m%d")
43
+
44
+ # Get all the campaigns for this account.
45
+ selector = {
46
+ :fields => ['Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr'],
47
+ :predicates => [
48
+ {:field => 'Impressions', :operator => 'GREATER_THAN', :values => [0]}
49
+ ],
50
+ :date_range => {:min => start_date, :max => end_date},
51
+ :paging => {
52
+ :start_index => 0,
53
+ :number_results => PAGE_SIZE
54
+ }
55
+ }
56
+
57
+ # Set initial values.
58
+ offset, page = 0, {}
59
+
60
+ begin
61
+ page = campaign_srv.get(selector)
62
+ if page[:entries]
63
+ page[:entries].each do |campaign|
64
+ puts ("Campaign with ID %d, name '%s' had the following stats during" +
65
+ " the last week: ") % [campaign[:id], campaign[:name]]
66
+ stats = campaign[:campaign_stats]
67
+ puts "\tImpressions: %d" % stats[:impressions]
68
+ puts "\tClicks: %d" % stats[:clicks]
69
+ puts "\tCost: %.2f" % (stats[:cost][:micro_amount] / 1000000)
70
+ puts "\tCTR: %.2f%%" % (stats[:ctr] * 100)
71
+ end
72
+ # Increment values to request the next page.
73
+ offset += PAGE_SIZE
74
+ selector[:paging][:start_index] = offset
75
+ end
76
+ end while page[:total_num_entries] > offset
77
+
78
+ if page.include?(:total_num_entries)
79
+ puts "Total number of campaigns found: %d." % [page[:total_num_entries]]
80
+ end
81
+ end
82
+
83
+ if __FILE__ == $0
84
+ API_VERSION = :v201302
85
+ PAGE_SIZE = 500
86
+
87
+ begin
88
+ get_campaign_stats()
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,71 @@
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 gets the list of possible report fields for a report type.
22
+ #
23
+ # Tags: ReportDefinitionService.getReportFields
24
+
25
+ require 'adwords_api'
26
+
27
+ def get_report_fields(report_type)
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
+ report_def_srv = adwords.service(:ReportDefinitionService, API_VERSION)
37
+
38
+ # Get report fields.
39
+ fields = report_def_srv.get_report_fields(report_type)
40
+ if fields
41
+ puts "Report type '%s' contains the following fields:" % report_type
42
+ fields.each do |field|
43
+ puts ' - %s (%s)' % [field[:field_name], field[:field_type]]
44
+ puts ' := [%s]' % field[:enum_values].join(', ') if field[:enum_values]
45
+ end
46
+ end
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ API_VERSION = :v201302
51
+
52
+ begin
53
+ report_type = 'INSERT_REPORT_TYPE_HERE'
54
+ get_report_fields(report_type)
55
+
56
+ # HTTP errors.
57
+ rescue AdsCommon::Errors::HttpError => e
58
+ puts "HTTP Error: %s" % e
59
+
60
+ # API errors.
61
+ rescue AdwordsApi::Errors::ApiException => e
62
+ puts "Message: %s" % e.message
63
+ puts 'Errors:'
64
+ e.errors.each_with_index do |error, index|
65
+ puts "\tError [%d]:" % (index + 1)
66
+ error.each do |field, value|
67
+ puts "\t\t%s: %s" % [field, value]
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,107 @@
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 adds various types of targeting criteria to a campaign. To get
22
+ # campaigns list, run get_campaigns.rb.
23
+ #
24
+ # Tags: CampaignCriterionService.mutate
25
+
26
+ require 'adwords_api'
27
+
28
+ def add_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
+ # Create campaign criteria.
41
+ campaign_criteria = [
42
+ # Location criteria. The IDs can be found in the documentation or retrieved
43
+ # with the LocationCriterionService.
44
+ {:xsi_type => 'Location', :id => 21137}, # California, USA
45
+ {:xsi_type => 'Location', :id => 2484}, # Mexico
46
+ # Language criteria. The IDs can be found in the documentation or retrieved
47
+ # with the ConstantDataService.
48
+ {:xsi_type => 'Language', :id => 1000}, # English
49
+ {:xsi_type => 'Language', :id => 1003} # Spanish
50
+ ]
51
+
52
+ # Create operations.
53
+ operations = campaign_criteria.map do |criterion|
54
+ {:operator => 'ADD',
55
+ :operand => {
56
+ :campaign_id => campaign_id,
57
+ :criterion => criterion}
58
+ }
59
+ end
60
+
61
+ # Create operation to add a negative campaign placement.
62
+ operations << {
63
+ :operator => 'ADD',
64
+ :operand => {
65
+ :xsi_type => 'NegativeCampaignCriterion',
66
+ :campaign_id => campaign_id,
67
+ :criterion => {
68
+ :xsi_type => 'Placement',
69
+ :url => 'http://mars.google.com'
70
+ }
71
+ }
72
+ }
73
+
74
+ response = campaign_criterion_srv.mutate(operations)
75
+
76
+ criteria = response[:value]
77
+ criteria.each do |campaign_criterion|
78
+ criterion = campaign_criterion[:criterion]
79
+ puts ("Campaign criterion with campaign ID %d, criterion ID %d and " +
80
+ "type '%s' was added.") % [campaign_criterion[:campaign_id],
81
+ criterion[:id], criterion[:criterion_type]]
82
+ end
83
+ end
84
+
85
+ if __FILE__ == $0
86
+ API_VERSION = :v201302
87
+
88
+ begin
89
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'
90
+ add_campaign_targeting_criteria(campaign_id)
91
+
92
+ # HTTP errors.
93
+ rescue AdsCommon::Errors::HttpError => e
94
+ puts "HTTP Error: %s" % e
95
+
96
+ # API errors.
97
+ rescue AdwordsApi::Errors::ApiException => e
98
+ puts "Message: %s" % e.message
99
+ puts 'Errors:'
100
+ e.errors.each_with_index do |error, index|
101
+ puts "\tError [%d]:" % (index + 1)
102
+ error.each do |field, value|
103
+ puts "\t\t%s: %s" % [field, value]
104
+ end
105
+ end
106
+ end
107
+ 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 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', 'PlacementUrl'],
43
+ :predicates => [
44
+ {:field => 'CampaignId', :operator => 'EQUALS', :values => [campaign_id]},
45
+ {
46
+ :field => 'CriteriaType',
47
+ :operator => 'EQUALS',
48
+ :values => ['PLACEMENT']
49
+ }
50
+ ],
51
+ :paging => {
52
+ :start_index => 0,
53
+ :number_results => PAGE_SIZE
54
+ }
55
+ }
56
+
57
+ # Set initial values.
58
+ offset, page = 0, {}
59
+
60
+ begin
61
+ page = campaign_criterion_srv.get(selector)
62
+ if page[:entries]
63
+ page[:entries].each do |criterion|
64
+ placement = criterion[:criterion]
65
+ puts "Placement with ID %d, type '%s' and URL '%s' was found." %
66
+ [placement[:id], placement[:type], placement[:url]]
67
+ end
68
+ # Increment values to request the next page.
69
+ offset += PAGE_SIZE
70
+ selector[:paging][:start_index] = offset
71
+ end
72
+ end while page[:total_num_entries] > offset
73
+
74
+ if page.include?(:total_num_entries)
75
+ puts "\tCampaign ID %d has %d placements." %
76
+ [campaign_id, page[:total_num_entries]]
77
+ end
78
+ end
79
+
80
+ if __FILE__ == $0
81
+ API_VERSION = :v201302
82
+ PAGE_SIZE = 500
83
+
84
+ begin
85
+ # Specify campaign ID to get targeting for.
86
+ campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
87
+ get_campaign_targeting_criteria(campaign_id)
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