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,97 @@
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 use OAuth2.0 authentication method.
22
+ #
23
+ # Tags: CampaignService.get
24
+
25
+ require 'adwords_api'
26
+
27
+ def use_oauth2()
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
+ # You can call authorize explicitely to obtain the access token. Otherwise, it
37
+ # will be invoked automatically on the first API call.
38
+ # There are two ways to provide verification code, first one is via the block:
39
+ token = adwords.authorize() do |auth_url|
40
+ puts "Hit Auth error, please navigate to URL:\n\t%s" % auth_url
41
+ print 'log in and type the verification code: '
42
+ verification_code = gets.chomp
43
+ verification_code
44
+ end
45
+ # Alternatively, you can provide one within the parameters:
46
+ #token = adwords.authorize({:oauth2_verification_code => verification_code})
47
+
48
+ # Note, 'token' is a Hash. Its value is not used in this example. If you need
49
+ # to be able to access the API in offline mode, with no user present, you
50
+ # should persist it to be used in subsequent invocations like this:
51
+ #adwords.authorize({:oauth2_token => token})
52
+
53
+ # No exception thrown - we are good to make the request.
54
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
55
+
56
+ # Get all the campaigns for this account; empty selector.
57
+ selector = {
58
+ :fields => ['Id', 'Name', 'Status'],
59
+ :ordering => [
60
+ {:field => 'Name', :sort_order => 'ASCENDING'}
61
+ ]
62
+ }
63
+
64
+ response = campaign_srv.get(selector)
65
+ if response and response[:entries]
66
+ campaigns = response[:entries]
67
+ campaigns.each do |campaign|
68
+ puts "Campaign ID %d, name '%s' and status '%s'" %
69
+ [campaign[:id], campaign[:name], campaign[:status]]
70
+ end
71
+ else
72
+ puts 'No campaigns were found.'
73
+ end
74
+ end
75
+
76
+ if __FILE__ == $0
77
+ API_VERSION = :v201302
78
+
79
+ begin
80
+ use_oauth2()
81
+
82
+ # HTTP errors.
83
+ rescue AdsCommon::Errors::HttpError => e
84
+ puts "HTTP Error: %s" % e
85
+
86
+ # API errors.
87
+ rescue AdwordsApi::Errors::ApiException => e
88
+ puts "Message: %s" % e.message
89
+ puts 'Errors:'
90
+ e.errors.each_with_index do |error, index|
91
+ puts "\tError [%d]:" % (index + 1)
92
+ error.each do |field, value|
93
+ puts "\t\t%s: %s" % [field, value]
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,93 @@
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 use OAuth2.0 authentication method with
22
+ # Service Account (JWT).
23
+ #
24
+ # Tags: CampaignService.get
25
+
26
+ require 'adwords_api'
27
+
28
+ def use_oauth2_jwt()
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
+ # Option 1: provide key filename as authentication -> oauth2_keyfile in the
38
+ # configuration file. No additional code is necessary.
39
+ # To provide a file name at runtime, use authorize:
40
+ # adwords.authorize({:oauth2_keyfile => key_filename})
41
+
42
+ # Option 2: retrieve key manually and create OpenSSL::PKCS12 object.
43
+ # key_filename = 'INSERT_FILENAME_HERE'
44
+ # key_secret = 'INSERT_SECRET_HERE'
45
+ # key_file_data = File.read(key_filename)
46
+ # key = OpenSSL::PKCS12.new(key_file_data, key_secret).key
47
+ # adwords.authorize({:oauth2_key => key})
48
+
49
+ # Now you can make API calls.
50
+ campaign_srv = adwords.service(:CampaignService, API_VERSION)
51
+
52
+ # Get all the campaigns for this account; empty selector.
53
+ selector = {
54
+ :fields => ['Id', 'Name', 'Status'],
55
+ :ordering => [
56
+ {:field => 'Name', :sort_order => 'ASCENDING'}
57
+ ]
58
+ }
59
+
60
+ response = campaign_srv.get(selector)
61
+ if response and response[:entries]
62
+ campaigns = response[:entries]
63
+ campaigns.each do |campaign|
64
+ puts "Campaign ID %d, name '%s' and status '%s'" %
65
+ [campaign[:id], campaign[:name], campaign[:status]]
66
+ end
67
+ else
68
+ puts 'No campaigns were found.'
69
+ end
70
+ end
71
+
72
+ if __FILE__ == $0
73
+ API_VERSION = :v201302
74
+
75
+ begin
76
+ use_oauth2_jwt()
77
+
78
+ # HTTP errors.
79
+ rescue AdsCommon::Errors::HttpError => e
80
+ puts "HTTP Error: %s" % e
81
+
82
+ # API errors.
83
+ rescue AdwordsApi::Errors::ApiException => e
84
+ puts "Message: %s" % e.message
85
+ puts 'Errors:'
86
+ e.errors.each_with_index do |error, index|
87
+ puts "\tError [%d]:" % (index + 1)
88
+ error.each do |field, value|
89
+ puts "\t\t%s: %s" % [field, value]
90
+ end
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,104 @@
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 retrieves URLs that have content keywords related to a given
22
+ # website.
23
+ #
24
+ # Tags: TargetingIdeaService.get
25
+
26
+ require 'adwords_api'
27
+
28
+ def get_placement_ideas(url)
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
+ targeting_idea_srv = adwords.service(:TargetingIdeaService, API_VERSION)
38
+
39
+ # Construct selector.
40
+ selector = {
41
+ :idea_type => 'PLACEMENT',
42
+ :request_type => 'IDEAS',
43
+ :requested_attribute_types => ['CRITERION'],
44
+ :search_parameters => [{
45
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
46
+ # being created. It's only necessary when you must provide an explicit
47
+ # type that the client library can't infer.
48
+ :xsi_type => 'RelatedToUrlSearchParameter',
49
+ :urls => [url],
50
+ :include_sub_urls => false
51
+ }],
52
+ :paging => {
53
+ :start_index => 0,
54
+ :number_results => PAGE_SIZE
55
+ }
56
+ }
57
+
58
+ # Define initial values.
59
+ offset = 0
60
+ results = []
61
+
62
+ begin
63
+ # Perform request.
64
+ page = targeting_idea_srv.get(selector)
65
+ results += page[:entries] if page and page[:entries]
66
+
67
+ # Prepare next page request.
68
+ offset += PAGE_SIZE
69
+ selector[:paging][:start_index] = offset
70
+ end while offset < page[:total_num_entries]
71
+
72
+ # Display results.
73
+ results.each do |result|
74
+ placement = result[:data]['CRITERION'][:value]
75
+ puts "Related placement found at URL [%s]" % placement[:url]
76
+ end
77
+ puts "Total URLs found with keywords related to keywords at [%s]: %d." %
78
+ [url, results.length]
79
+ end
80
+
81
+ if __FILE__ == $0
82
+ API_VERSION = :v201302
83
+ PAGE_SIZE = 100
84
+
85
+ begin
86
+ url = 'INSERT_PLACEMENT_URL_HERE'
87
+ get_placement_ideas(url)
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
@@ -0,0 +1,115 @@
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 create a user list (a.k.a. Audience) and shows
22
+ # its associated conversion tracker code snippet.
23
+ #
24
+ # Tags: UserListService.mutate, ConversionTrackerService.get
25
+
26
+ require 'adwords_api'
27
+
28
+ def add_audience()
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
+ user_list_srv = adwords.service(:UserListService, API_VERSION)
38
+ conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
39
+
40
+ # Prepare for adding remarketing user list.
41
+ name = "Mars cruise customers #%d" % (Time.new.to_f * 1000).to_i
42
+ operation = {
43
+ :operator => 'ADD',
44
+ :operand => {
45
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
46
+ # being created. It's only necessary when you must provide an explicit
47
+ # type that the client library can't infer.
48
+ :xsi_type => 'RemarketingUserList',
49
+ :name => name,
50
+ :description => 'A list of mars cruise customers in the last year',
51
+ :status => 'OPEN',
52
+ :membership_life_span => 365,
53
+ :conversion_types => [{:name => name}],
54
+ # Optional field.
55
+ :status => 'OPEN'
56
+ }
57
+ }
58
+
59
+ # Add user list.
60
+ response = user_list_srv.mutate([operation])
61
+ if response and response[:value]
62
+ user_list = response[:value].first
63
+
64
+ # Get conversion snippets.
65
+ if user_list and user_list[:conversion_types]
66
+ conversion_ids = user_list[:conversion_types].map {|type| type[:id]}
67
+ selector = {
68
+ # We're actually interested in the 'Snippet' field, which is returned
69
+ # automatically.
70
+ :fields => ['Id'],
71
+ :predicates => [
72
+ {:field => 'Id', :operator => 'IN', :values => conversion_ids}
73
+ ]
74
+ }
75
+ conv_tracker_response = conv_tracker_srv.get(selector)
76
+ if conv_tracker_response and conv_tracker_response[:entries]
77
+ conversions = conv_tracker_response[:entries]
78
+ end
79
+ end
80
+ puts "User list with name '%s' and ID %d was added." %
81
+ [user_list[:name], user_list[:id]]
82
+ # Display user list associated conversion code snippets.
83
+ if conversions
84
+ conversions.each do |conversion|
85
+ puts "Conversion type code snipped associated to the list:\n\t\t%s\n" %
86
+ conversion[:snippet]
87
+ end
88
+ end
89
+ else
90
+ puts 'No user lists were added.'
91
+ end
92
+ end
93
+
94
+ if __FILE__ == $0
95
+ API_VERSION = :v201302
96
+
97
+ begin
98
+ add_audience()
99
+
100
+ # HTTP errors.
101
+ rescue AdsCommon::Errors::HttpError => e
102
+ puts "HTTP Error: %s" % e
103
+
104
+ # API errors.
105
+ rescue AdwordsApi::Errors::ApiException => e
106
+ puts "Message: %s" % e.message
107
+ puts 'Errors:'
108
+ e.errors.each_with_index do |error, index|
109
+ puts "\tError [%d]:" % (index + 1)
110
+ error.each do |field, value|
111
+ puts "\t\t%s: %s" % [field, value]
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,96 @@
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 add an AdWords conversion tracker.
22
+ #
23
+ # Tags: ConversionTrackerService.mutate
24
+
25
+ require 'adwords_api'
26
+
27
+ def add_conversion_tracker()
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
+ conv_tracker_srv = adwords.service(:ConversionTrackerService, API_VERSION)
37
+
38
+ # Prepare for adding conversion.
39
+ operation = {
40
+ :operator => 'ADD',
41
+ :operand => {
42
+ # The 'xsi_type' field allows you to specify the xsi:type of the object
43
+ # being created. It's only necessary when you must provide an explicit
44
+ # type that the client library can't infer.
45
+ :xsi_type => 'AdWordsConversionTracker',
46
+ :name => "Earth to Mars Cruises Conversion #%d" %
47
+ (Time.new.to_f * 1000).to_i,
48
+ :category => 'DEFAULT',
49
+ :markup_language => 'HTML',
50
+ :text_format => 'HIDDEN',
51
+ # Optional fields:
52
+ :status => 'ENABLED',
53
+ :viewthrough_lookback_window => 15,
54
+ :viewthrough_conversion_de_dup_search => true,
55
+ :is_product_ads_chargeable => true,
56
+ :product_ads_chargeable_conversion_window => 15,
57
+ :conversion_page_language => 'en',
58
+ :background_color => '#0000FF',
59
+ :user_revenue_value => 'someJavascriptVariable'
60
+ }
61
+ }
62
+
63
+ # Add conversion.
64
+ response = conv_tracker_srv.mutate([operation])
65
+ if response and response[:value]
66
+ conversion = response[:value].first
67
+ puts ("Conversion with ID %d, name '%s', status '%s' and category '%s'" +
68
+ " was added.") % [conversion[:id], conversion[:name],
69
+ conversion[:status], conversion[:category]]
70
+ else
71
+ puts 'No conversions were added.'
72
+ end
73
+ end
74
+
75
+ if __FILE__ == $0
76
+ API_VERSION = :v201302
77
+
78
+ begin
79
+ add_conversion_tracker()
80
+
81
+ # HTTP errors.
82
+ rescue AdsCommon::Errors::HttpError => e
83
+ puts "HTTP Error: %s" % e
84
+
85
+ # API errors.
86
+ rescue AdwordsApi::Errors::ApiException => e
87
+ puts "Message: %s" % e.message
88
+ puts 'Errors:'
89
+ e.errors.each_with_index do |error, index|
90
+ puts "\tError [%d]:" % (index + 1)
91
+ error.each do |field, value|
92
+ puts "\t\t%s: %s" % [field, value]
93
+ end
94
+ end
95
+ end
96
+ end