google-adwords-api 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +3 -0
- data/README +33 -22
- data/adwords_api.yml +5 -5
- data/examples/v201302/adwords_for_video/add_video_call_to_action.rb +94 -0
- data/examples/v201302/adwords_for_video/add_video_campaign.rb +103 -0
- data/examples/v201302/adwords_for_video/find_videos.rb +92 -0
- data/examples/v201302/adwords_for_video/get_keyword_criteria.rb +101 -0
- data/examples/v201302/adwords_for_video/get_targeting_groups.rb +93 -0
- data/examples/v201302/adwords_for_video/get_video_campaign_criteria.rb +99 -0
- data/examples/v201302/adwords_for_video/get_video_campaign_stats.rb +126 -0
- data/examples/v201302/adwords_for_video/get_video_campaigns.rb +94 -0
- data/lib/adwords_api.rb +5 -5
- data/lib/adwords_api/api_config.rb +16 -2
- data/lib/adwords_api/v201302/video_ad_service.rb +38 -0
- data/lib/adwords_api/v201302/video_ad_service_registry.rb +46 -0
- data/lib/adwords_api/v201302/video_campaign_criterion_service.rb +38 -0
- data/lib/adwords_api/v201302/video_campaign_criterion_service_registry.rb +47 -0
- data/lib/adwords_api/v201302/video_campaign_service.rb +38 -0
- data/lib/adwords_api/v201302/video_campaign_service_registry.rb +46 -0
- data/lib/adwords_api/v201302/video_service.rb +42 -0
- data/lib/adwords_api/v201302/video_service_registry.rb +46 -0
- data/lib/adwords_api/v201302/video_targeting_group_criterion_service.rb +38 -0
- data/lib/adwords_api/v201302/video_targeting_group_criterion_service_registry.rb +46 -0
- data/lib/adwords_api/v201302/video_targeting_group_service.rb +38 -0
- data/lib/adwords_api/v201302/video_targeting_group_service_registry.rb +46 -0
- data/lib/adwords_api/version.rb +1 -1
- data/test/adwords_api/test_adwords_api.rb +23 -0
- data/test/templates/v201209/basic_operations_get_campaigns.def +1 -1
- data/test/templates/v201302/basic_operations_get_campaigns.def +1 -1
- data/test/templates/v201302/misc_use_oauth2_jwt.def +1 -1
- metadata +22 -2
data/ChangeLog
CHANGED
data/README
CHANGED
@@ -45,19 +45,24 @@ There is an example configuration file shipped with these libraries.
|
|
45
45
|
You can also pass API a manually constructed config hash like:
|
46
46
|
adwords = AdwordsApi::Api.new({
|
47
47
|
:authentication => {
|
48
|
-
:method => '
|
48
|
+
:method => 'OAuth2',
|
49
|
+
:oauth2_client_id: 'INSERT_OAUTH2_CLIENT_ID_HERE'
|
50
|
+
:oauth2_client_secret: 'INSERT_OAUTH2_CLIENT_SECRET_HERE'
|
49
51
|
:developer_token => 'DEVELOPER_TOKEN',
|
50
|
-
:
|
51
|
-
:
|
52
|
-
:email => 'user@domain.com',
|
53
|
-
:client_customer_id => '012-345-6789'
|
52
|
+
:client_customer_id => '012-345-6789',
|
53
|
+
:user_agent => 'Ruby Sample'
|
54
54
|
},
|
55
55
|
:service => {
|
56
56
|
:environment => 'PRODUCTION'
|
57
57
|
}
|
58
58
|
})
|
59
59
|
|
60
|
-
|
60
|
+
To obtain OAuth2 client credentials, follow instructions on the wiki:
|
61
|
+
|
62
|
+
http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2
|
63
|
+
|
64
|
+
Once the library instance is create, specify which service you're looking to
|
65
|
+
use, and which version:
|
61
66
|
campaign_srv = adwords.service(:CampaignService, :v201302)
|
62
67
|
|
63
68
|
and you should now be able to just use the API methods in the object you were
|
@@ -91,14 +96,12 @@ In order to make things more Ruby-like for our Ruby developers, we've renamed
|
|
91
96
|
API objects and methods to more closely match Ruby conventions. This means using
|
92
97
|
snake_case for methods and parameters, and UpperCamelCase for class names.
|
93
98
|
|
94
|
-
For example, the '
|
95
|
-
|
96
|
-
|
99
|
+
For example, the 'startDate' field of the Campaign object is named 'start_date'
|
100
|
+
in the client library. The 'get' method, returns a CampaignPage object which has
|
101
|
+
an 'entries' and a 'total_num_entries' field. So, to access the return
|
102
|
+
values, you would do this:
|
97
103
|
|
98
|
-
|
99
|
-
has an 'entries' and a 'total_num_entries' field. So, to access the return
|
100
|
-
values, you would do:
|
101
|
-
response = report_def_srv.get(selector)
|
104
|
+
response = campaign_srv.get(selector)
|
102
105
|
num_entries = response[:total_num_entries]
|
103
106
|
|
104
107
|
Essentially, all you have to do is follow Ruby conventions, and the library will
|
@@ -142,20 +145,23 @@ Request details and units spend are logged at the INFO log level, while raw HTTP
|
|
142
145
|
headers and XML dumps are logged at the DEBUG log level. For more details on
|
143
146
|
using Logger refer to the Ruby Logger documentation.
|
144
147
|
|
145
|
-
=== 2.4 - Calculating
|
148
|
+
=== 2.4 - Calculating operations usage
|
149
|
+
|
150
|
+
Each AdWords API operation performed consumes a certain number of operations as
|
151
|
+
described in the rate sheet:
|
146
152
|
|
147
|
-
|
148
|
-
specified in the rate sheet:
|
149
|
-
http://code.google.com/apis/adwords/docs/ratesheet.html
|
153
|
+
https://developers.google.com/adwords/api/docs/ratesheet
|
150
154
|
|
151
|
-
The amount of
|
152
|
-
This information can be obtained by passing a user block during
|
153
|
-
|
154
|
-
|
155
|
+
The amount of operations consumed is returned in the header part of the SOAP
|
156
|
+
response. This information can be obtained by passing a user block during the
|
157
|
+
method call:
|
158
|
+
|
159
|
+
response = campaign_srv.get(selector) do |header|
|
160
|
+
puts "Operations consumed: %d" % header[:operations]
|
155
161
|
end
|
156
162
|
|
157
163
|
You can also retrieve the response body as the second block parameter:
|
158
|
-
|
164
|
+
campaign_srv.get(selector) {|header, body| ... }
|
159
165
|
|
160
166
|
=== 2.5 - GZip compression
|
161
167
|
|
@@ -195,6 +201,11 @@ Questions can be asked on forum
|
|
195
201
|
|
196
202
|
http://groups.google.com/group/adwords-api
|
197
203
|
|
204
|
+
Make sure to subscribe to our Google Plus page for API change announcements and
|
205
|
+
other news:
|
206
|
+
|
207
|
+
https://plus.google.com/+GoogleAdsDevelopers
|
208
|
+
|
198
209
|
|
199
210
|
= Copyright/License Info
|
200
211
|
|
data/adwords_api.yml
CHANGED
@@ -4,14 +4,14 @@
|
|
4
4
|
:authentication:
|
5
5
|
# Authentication method, methods currently supported: OAUTH2, OAUTH2_JWT,
|
6
6
|
# ClientLogin.
|
7
|
-
:method:
|
7
|
+
:method: OAuth2
|
8
8
|
|
9
9
|
# Auth parameters for OAUTH2 method.
|
10
10
|
# Set the OAuth2 client id and secret. Register your application here to
|
11
11
|
# obtain these values:
|
12
12
|
# https://code.google.com/apis/console#access
|
13
|
-
|
14
|
-
|
13
|
+
:oauth2_client_id: INSERT_OAUTH2_CLIENT_ID_HERE
|
14
|
+
:oauth2_client_secret: INSERT_OAUTH2_CLIENT_SECRET_HERE
|
15
15
|
# Optional, see: https://developers.google.com/accounts/docs/OAuth2WebServer
|
16
16
|
#:oauth2_callback: INSERT_OAUTH2_CALLBACK_URL_HERE
|
17
17
|
#:oauth2_state: INSERT_OAUTH2_STATE_HERE
|
@@ -30,8 +30,8 @@
|
|
30
30
|
|
31
31
|
# Auth parameters for ClientLogin method.
|
32
32
|
# NOTE: ClientLogin method is deprecated, use OAuth2.0 instead.
|
33
|
-
|
34
|
-
|
33
|
+
#:password: INSERT_YOUR_PASSWORD_HERE
|
34
|
+
#:email: INSERT_YOUR_LOGIN_EMAIL_HERE
|
35
35
|
# To manage your auth tokens manually, use the 'auth_token' property.
|
36
36
|
#:auth_token: INSERT_AUTH_TOKEN_HERE
|
37
37
|
|
@@ -0,0 +1,94 @@
|
|
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 create a video call to action overlay.
|
22
|
+
#
|
23
|
+
# Note: AdWords for Video API is a Beta feature.
|
24
|
+
#
|
25
|
+
# Tags: VideoService.mutateCallToAction
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
|
29
|
+
def add_video_call_to_action(video_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
|
+
video_srv = adwords.service(:VideoService, API_VERSION)
|
39
|
+
|
40
|
+
# Create VideoCallToAction locally.
|
41
|
+
video_call_to_action = {
|
42
|
+
:id => video_id,
|
43
|
+
:call_to_action => {
|
44
|
+
:creative => {
|
45
|
+
:headline => 'Mars cruises',
|
46
|
+
:description_line1 => 'Astonishing views',
|
47
|
+
:description_line2 => 'Mild climate',
|
48
|
+
:display_url => 'www.example.com/mars',
|
49
|
+
:destination_url => 'www.example.com/mars'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
# Run a mutate request with ADD operator.
|
55
|
+
response = video_srv.mutate_call_to_action([
|
56
|
+
{:operator => 'SET', :operand => video_call_to_action}
|
57
|
+
])
|
58
|
+
|
59
|
+
if response and response[:value]
|
60
|
+
response[:value].each do |video_call_to_action|
|
61
|
+
puts "CallToAction overlay was added to video ID '%s', headline '%s'." %
|
62
|
+
[video_call_to_action[:id],
|
63
|
+
video_call_to_action[:call_to_action][:creative][:headline]]
|
64
|
+
end
|
65
|
+
else
|
66
|
+
raise new StandardError, 'No call to action overlays were added.'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if __FILE__ == $0
|
71
|
+
API_VERSION = :v201302
|
72
|
+
|
73
|
+
begin
|
74
|
+
# Video ID to add call to action to.
|
75
|
+
video_id = 'INSERT_VIDEO_ID_HERE'
|
76
|
+
|
77
|
+
add_video_call_to_action(video_id)
|
78
|
+
|
79
|
+
# HTTP errors.
|
80
|
+
rescue AdsCommon::Errors::HttpError => e
|
81
|
+
puts "HTTP Error: %s" % e
|
82
|
+
|
83
|
+
# API errors.
|
84
|
+
rescue AdwordsApi::Errors::ApiException => e
|
85
|
+
puts "Message: %s" % e.message
|
86
|
+
puts 'Errors:'
|
87
|
+
e.errors.each_with_index do |error, index|
|
88
|
+
puts "\tError [%d]:" % (index + 1)
|
89
|
+
error.each do |field, value|
|
90
|
+
puts "\t\t%s: %s" % [field, value]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,103 @@
|
|
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 create a video campaign.
|
22
|
+
#
|
23
|
+
# Note: AdWords for Video API is a Beta feature.
|
24
|
+
#
|
25
|
+
# Tags: VideoCampaignService.mutate, BudgetService.mutate
|
26
|
+
|
27
|
+
require 'adwords_api'
|
28
|
+
require 'date'
|
29
|
+
|
30
|
+
def add_video_campaign()
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
|
35
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
36
|
+
# the configuration file or provide your own logger:
|
37
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
38
|
+
|
39
|
+
budget_srv = adwords.service(:BudgetService, API_VERSION)
|
40
|
+
video_campaign_srv = adwords.service(:VideoCampaignService, API_VERSION)
|
41
|
+
|
42
|
+
# Create a budget, which can be shared by multiple campaigns.
|
43
|
+
budget = {
|
44
|
+
:name => 'Video budget #%d' % (Time.new.to_f * 1000).to_i,
|
45
|
+
:amount => {:micro_amount => 50000000},
|
46
|
+
:delivery_method => 'STANDARD',
|
47
|
+
:period => 'DAILY'
|
48
|
+
}
|
49
|
+
budget_operation = {:operator => 'ADD', :operand => budget}
|
50
|
+
|
51
|
+
# Add budget.
|
52
|
+
return_budget = budget_srv.mutate([budget_operation])
|
53
|
+
budget_id = return_budget[:value].first[:budget_id]
|
54
|
+
|
55
|
+
# Create video campaign.
|
56
|
+
campaigns = [{
|
57
|
+
:name => "Interplanetary Video #%d" % (Time.new.to_f * 1000).to_i,
|
58
|
+
:status => 'PAUSED',
|
59
|
+
:budget_id => budget_id,
|
60
|
+
# Optional fields:
|
61
|
+
:start_date =>
|
62
|
+
DateTime.parse((Date.today + 1).to_s).strftime('%Y%m%d'),
|
63
|
+
}]
|
64
|
+
|
65
|
+
# Prepare for adding campaign.
|
66
|
+
operations = campaigns.map do |campaign|
|
67
|
+
{:operator => 'ADD', :operand => campaign}
|
68
|
+
end
|
69
|
+
|
70
|
+
# Add video campaign.
|
71
|
+
response = video_campaign_srv.mutate(operations)
|
72
|
+
if response and response[:value]
|
73
|
+
response[:value].each do |campaign|
|
74
|
+
puts "Campaign with name '%s' and ID %d was added." %
|
75
|
+
[campaign[:name], campaign[:id]]
|
76
|
+
end
|
77
|
+
else
|
78
|
+
raise new StandardError, 'No campaigns were added.'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
if __FILE__ == $0
|
83
|
+
API_VERSION = :v201302
|
84
|
+
|
85
|
+
begin
|
86
|
+
add_video_campaign()
|
87
|
+
|
88
|
+
# HTTP errors.
|
89
|
+
rescue AdsCommon::Errors::HttpError => e
|
90
|
+
puts "HTTP Error: %s" % e
|
91
|
+
|
92
|
+
# API errors.
|
93
|
+
rescue AdwordsApi::Errors::ApiException => e
|
94
|
+
puts "Message: %s" % e.message
|
95
|
+
puts 'Errors:'
|
96
|
+
e.errors.each_with_index do |error, index|
|
97
|
+
puts "\tError [%d]:" % (index + 1)
|
98
|
+
error.each do |field, value|
|
99
|
+
puts "\t\t%s: %s" % [field, value]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Encoding: utf-8
|
3
|
+
#
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
|
+
#
|
6
|
+
# Copyright:: Copyright 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 find YouTube videos by a search string. It
|
22
|
+
# retrieve details for the first 100 matching videos.
|
23
|
+
#
|
24
|
+
# Note: AdWords for Video API is a Beta feature.
|
25
|
+
#
|
26
|
+
# Tags: VideoService.search
|
27
|
+
|
28
|
+
require 'adwords_api'
|
29
|
+
|
30
|
+
def find_videos()
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
|
35
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
36
|
+
# the configuration file or provide your own logger:
|
37
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
38
|
+
|
39
|
+
video_srv = adwords.service(:VideoService, API_VERSION)
|
40
|
+
|
41
|
+
# Search string to use.
|
42
|
+
query_str = 'AdWords API with Ruby'
|
43
|
+
|
44
|
+
# Create a selector.
|
45
|
+
selector = {
|
46
|
+
:search_type => 'VIDEO',
|
47
|
+
:query => query_str,
|
48
|
+
:paging => {
|
49
|
+
:start_index => 0,
|
50
|
+
:number_results => PAGE_SIZE
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
# Run the query.
|
55
|
+
page = video_srv.search(selector)
|
56
|
+
|
57
|
+
if page[:entries]
|
58
|
+
page[:entries].each do |video|
|
59
|
+
puts "YouTube video ID '%s' with title '%s' found." %
|
60
|
+
[video[:id], video[:title]]
|
61
|
+
end
|
62
|
+
if page.include?(:total_num_entries)
|
63
|
+
puts "\tTotal number of matching videos: %d." % [page[:total_num_entries]]
|
64
|
+
end
|
65
|
+
else
|
66
|
+
puts "No videos matching '%s' were found." % query_str
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
if __FILE__ == $0
|
71
|
+
API_VERSION = :v201302
|
72
|
+
PAGE_SIZE = 100
|
73
|
+
|
74
|
+
begin
|
75
|
+
find_videos()
|
76
|
+
|
77
|
+
# HTTP errors.
|
78
|
+
rescue AdsCommon::Errors::HttpError => e
|
79
|
+
puts "HTTP Error: %s" % e
|
80
|
+
|
81
|
+
# API errors.
|
82
|
+
rescue AdwordsApi::Errors::ApiException => e
|
83
|
+
puts "Message: %s" % e.message
|
84
|
+
puts 'Errors:'
|
85
|
+
e.errors.each_with_index do |error, index|
|
86
|
+
puts "\tError [%d]:" % (index + 1)
|
87
|
+
error.each do |field, value|
|
88
|
+
puts "\t\t%s: %s" % [field, value]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,101 @@
|
|
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 show how to retrieve all keywords for a video campaign. To get
|
22
|
+
# a list with all campaigns, run get_video_campaigns.rb.
|
23
|
+
#
|
24
|
+
# Note: AdWords for Video API is a Beta feature.
|
25
|
+
#
|
26
|
+
# Tags: VideoTargetingGroupCriterionService.get
|
27
|
+
|
28
|
+
require 'adwords_api'
|
29
|
+
|
30
|
+
def get_keyword_criteria(campaign_id)
|
31
|
+
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
32
|
+
# when called without parameters.
|
33
|
+
adwords = AdwordsApi::Api.new
|
34
|
+
|
35
|
+
# To enable logging of SOAP requests, set the log_level value to 'DEBUG' in
|
36
|
+
# the configuration file or provide your own logger:
|
37
|
+
# adwords.logger = Logger.new('adwords_xml.log')
|
38
|
+
|
39
|
+
vtgc_srv =
|
40
|
+
adwords.service(:VideoTargetingGroupCriterionService, API_VERSION)
|
41
|
+
|
42
|
+
# Get all the keywords for the campaign.
|
43
|
+
selector = {
|
44
|
+
:campaign_ids => [campaign_id],
|
45
|
+
:criterion_types => ['SEARCH_KEYWORD'],
|
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 = vtgc_srv.get(selector)
|
57
|
+
if page[:entries]
|
58
|
+
page[:entries].each do |keyword|
|
59
|
+
negative_string =
|
60
|
+
('NegativeTargetingGroupCriterion'.eql?(keyword[:xsi_type])) ?
|
61
|
+
' (negative)' : ''
|
62
|
+
puts "Criterion%s ID %d, targeting group ID %d and text '%s'" %
|
63
|
+
[negative_string, keyword[:criterion][:id],
|
64
|
+
keyword[:targeting_group_id], keyword[: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 "\tTotal number of keywords found: %d." % [page[:total_num_entries]]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
if __FILE__ == $0
|
78
|
+
API_VERSION = :v201302
|
79
|
+
PAGE_SIZE = 500
|
80
|
+
|
81
|
+
begin
|
82
|
+
# Campaign ID to get criteria for.
|
83
|
+
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
84
|
+
get_keyword_criteria(campaign_id)
|
85
|
+
|
86
|
+
# HTTP errors.
|
87
|
+
rescue AdsCommon::Errors::HttpError => e
|
88
|
+
puts "HTTP Error: %s" % e
|
89
|
+
|
90
|
+
# API errors.
|
91
|
+
rescue AdwordsApi::Errors::ApiException => e
|
92
|
+
puts "Message: %s" % e.message
|
93
|
+
puts 'Errors:'
|
94
|
+
e.errors.each_with_index do |error, index|
|
95
|
+
puts "\tError [%d]:" % (index + 1)
|
96
|
+
error.each do |field, value|
|
97
|
+
puts "\t\t%s: %s" % [field, value]
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|