google-adx-buyer-api 0.4.6 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +5 -0
- data/README +35 -24
- data/examples/{v201206 → v201306}/account_management/get_account_changes.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/add_ad_group.rb +19 -11
- data/examples/{v201206 → v201306}/basic_operations/add_campaign.rb +27 -14
- data/examples/{v201206 → v201306}/basic_operations/add_placements.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/add_thirdparty_redirect_ad.rb +16 -6
- data/examples/{v201206 → v201306}/basic_operations/delete_ad.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/delete_ad_group.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/delete_campaign.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/delete_placement.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/get_ad_groups.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/get_campaigns.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/get_placements.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/get_thirdparty_redirect_ads.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/pause_ad.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/update_ad_group.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/update_campaign.rb +9 -1
- data/examples/{v201206 → v201306}/basic_operations/update_placement.rb +15 -7
- data/examples/{v201206 → v201306}/campaign_management/add_placements_in_bulk.rb +10 -2
- data/examples/{v201206 → v201306}/campaign_management/get_all_disapproved_ads.rb +10 -2
- data/examples/{v201206 → v201306}/error_handling/handle_captcha_challenge.rb +1 -1
- data/examples/{v201206 → v201306}/error_handling/handle_partial_failures.rb +9 -1
- data/examples/{v201206 → v201306}/error_handling/handle_policy_violation_error.rb +9 -1
- data/examples/{v201206 → v201306}/error_handling/handle_two_factor_authorization_error.rb +3 -2
- data/examples/{v201206 → v201306}/misc/get_all_images_and_videos.rb +12 -5
- data/examples/v201306/misc/setup_oauth2.rb +88 -0
- data/examples/{v201206 → v201306}/misc/upload_image.rb +20 -10
- data/examples/{v201206/misc/use_oauth.rb → v201306/misc/use_oauth2_jwt.rb} +20 -24
- data/examples/{v201206 → v201306}/optimization/get_placement_ideas.rb +10 -4
- data/examples/{v201206 → v201306}/remarketing/add_audience.rb +38 -26
- data/examples/{v201206 → v201306}/remarketing/add_conversion_tracker.rb +17 -6
- data/examples/{v201206 → v201306}/reporting/download_criteria_report.rb +9 -1
- data/examples/{v201206 → v201306}/reporting/get_campaign_stats.rb +9 -1
- data/examples/{v201206 → v201306}/reporting/get_report_fields.rb +9 -1
- data/examples/{v201206 → v201306}/targeting/add_campaign_targeting_criteria.rb +10 -5
- data/examples/{v201206 → v201306}/targeting/get_campaign_targeting_criteria.rb +9 -1
- data/examples/{v201206 → v201306}/targeting/get_targetable_languages_and_carriers.rb +16 -4
- data/examples/{v201206 → v201306}/targeting/lookup_location.rb +9 -1
- metadata +41 -41
- data/examples/v201206/reporting/parallel_report_download.rb +0 -159
@@ -68,12 +68,20 @@ def get_placements(ad_group_id)
|
|
68
68
|
end
|
69
69
|
|
70
70
|
if __FILE__ == $0
|
71
|
-
API_VERSION = :
|
71
|
+
API_VERSION = :v201306
|
72
72
|
|
73
73
|
begin
|
74
74
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
75
75
|
get_placements(ad_group_id)
|
76
76
|
|
77
|
+
# Authorization error.
|
78
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
79
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
80
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
81
|
+
"to retrieve and store OAuth2 tokens."
|
82
|
+
puts "See this wiki page for more details:\n\n " +
|
83
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
84
|
+
|
77
85
|
# HTTP errors.
|
78
86
|
rescue AdsCommon::Errors::HttpError => e
|
79
87
|
puts "HTTP Error: %s" % e
|
@@ -76,12 +76,20 @@ def get_all_ads(ad_group_id)
|
|
76
76
|
end
|
77
77
|
|
78
78
|
if __FILE__ == $0
|
79
|
-
API_VERSION = :
|
79
|
+
API_VERSION = :v201306
|
80
80
|
|
81
81
|
begin
|
82
82
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
83
83
|
get_all_ads(ad_group_id)
|
84
84
|
|
85
|
+
# Authorization error.
|
86
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
87
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
88
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
89
|
+
"to retrieve and store OAuth2 tokens."
|
90
|
+
puts "See this wiki page for more details:\n\n " +
|
91
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
92
|
+
|
85
93
|
# HTTP errors.
|
86
94
|
rescue AdsCommon::Errors::HttpError => e
|
87
95
|
puts "HTTP Error: %s" % e
|
@@ -56,13 +56,21 @@ def pause_ad(ad_group_id, ad_id)
|
|
56
56
|
end
|
57
57
|
|
58
58
|
if __FILE__ == $0
|
59
|
-
API_VERSION = :
|
59
|
+
API_VERSION = :v201306
|
60
60
|
|
61
61
|
begin
|
62
62
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
63
63
|
ad_id = 'INSERT_AD_ID_HERE'.to_i
|
64
64
|
pause_ad(ad_group_id, ad_id)
|
65
65
|
|
66
|
+
# Authorization error.
|
67
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
68
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
69
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
70
|
+
"to retrieve and store OAuth2 tokens."
|
71
|
+
puts "See this wiki page for more details:\n\n " +
|
72
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
73
|
+
|
66
74
|
# HTTP errors.
|
67
75
|
rescue AdsCommon::Errors::HttpError => e
|
68
76
|
puts "HTTP Error: %s" % e
|
@@ -52,12 +52,20 @@ def update_ad_group(ad_group_id)
|
|
52
52
|
end
|
53
53
|
|
54
54
|
if __FILE__ == $0
|
55
|
-
API_VERSION = :
|
55
|
+
API_VERSION = :v201306
|
56
56
|
|
57
57
|
begin
|
58
58
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
59
59
|
update_ad_group(ad_group_id)
|
60
60
|
|
61
|
+
# Authorization error.
|
62
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
63
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
64
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
65
|
+
"to retrieve and store OAuth2 tokens."
|
66
|
+
puts "See this wiki page for more details:\n\n " +
|
67
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
68
|
+
|
61
69
|
# HTTP errors.
|
62
70
|
rescue AdsCommon::Errors::HttpError => e
|
63
71
|
puts "HTTP Error: %s" % e
|
@@ -55,12 +55,20 @@ def update_campaign(campaign_id)
|
|
55
55
|
end
|
56
56
|
|
57
57
|
if __FILE__ == $0
|
58
|
-
API_VERSION = :
|
58
|
+
API_VERSION = :v201306
|
59
59
|
|
60
60
|
begin
|
61
61
|
campaign_id = 'INSERT_CAMPAIGN_ID_HERE'.to_i
|
62
62
|
update_campaign(campaign_id)
|
63
63
|
|
64
|
+
# Authorization error.
|
65
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
66
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
67
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
68
|
+
"to retrieve and store OAuth2 tokens."
|
69
|
+
puts "See this wiki page for more details:\n\n " +
|
70
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
71
|
+
|
64
72
|
# HTTP errors.
|
65
73
|
rescue AdsCommon::Errors::HttpError => e
|
66
74
|
puts "HTTP Error: %s" % e
|
@@ -49,13 +49,13 @@ def update_placement(ad_group_id, placement_id)
|
|
49
49
|
:criterion => {
|
50
50
|
:id => placement_id
|
51
51
|
},
|
52
|
-
:
|
53
|
-
:
|
54
|
-
|
55
|
-
|
56
|
-
:micro_amount => 1000000
|
52
|
+
:bidding_strategy_configuration => {
|
53
|
+
:bids => [
|
54
|
+
{
|
55
|
+
:xsi_type => 'CpmBid',
|
56
|
+
:bid => {:micro_amount => 1000000}
|
57
57
|
}
|
58
|
-
|
58
|
+
]
|
59
59
|
}
|
60
60
|
}
|
61
61
|
}
|
@@ -69,13 +69,21 @@ def update_placement(ad_group_id, placement_id)
|
|
69
69
|
end
|
70
70
|
|
71
71
|
if __FILE__ == $0
|
72
|
-
API_VERSION = :
|
72
|
+
API_VERSION = :v201306
|
73
73
|
|
74
74
|
begin
|
75
75
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
76
76
|
placement_id = 'INSERT_PLACEMENT_ID_HERE'.to_i
|
77
77
|
update_placement(ad_group_id, placement_id)
|
78
78
|
|
79
|
+
# Authorization error.
|
80
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
81
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
82
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
83
|
+
"to retrieve and store OAuth2 tokens."
|
84
|
+
puts "See this wiki page for more details:\n\n " +
|
85
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
86
|
+
|
79
87
|
# HTTP errors.
|
80
88
|
rescue AdsCommon::Errors::HttpError => e
|
81
89
|
puts "HTTP Error: %s" % e
|
@@ -64,7 +64,7 @@ def add_placements_in_bulk(ad_group_id)
|
|
64
64
|
job_id = response[:id]
|
65
65
|
puts "Job ID %d was successfully created." % job_id
|
66
66
|
|
67
|
-
# Creating selector to retrive
|
67
|
+
# Creating selector to retrive job status and wait for it to complete.
|
68
68
|
selector = {
|
69
69
|
:xsi_type => 'BulkMutateJobSelector',
|
70
70
|
:job_ids => [job_id]
|
@@ -124,7 +124,7 @@ def add_placements_in_bulk(ad_group_id)
|
|
124
124
|
end
|
125
125
|
|
126
126
|
if __FILE__ == $0
|
127
|
-
API_VERSION = :
|
127
|
+
API_VERSION = :v201306
|
128
128
|
RETRY_INTERVAL = 30
|
129
129
|
RETRIES_COUNT = 30
|
130
130
|
PLACEMENT_NUMBER = 100
|
@@ -133,6 +133,14 @@ if __FILE__ == $0
|
|
133
133
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
134
134
|
add_placements_in_bulk(ad_group_id)
|
135
135
|
|
136
|
+
# Authorization error.
|
137
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
138
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
139
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
140
|
+
"to retrieve and store OAuth2 tokens."
|
141
|
+
puts "See this wiki page for more details:\n\n " +
|
142
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
143
|
+
|
136
144
|
# HTTP errors.
|
137
145
|
rescue AdsCommon::Errors::HttpError => e
|
138
146
|
puts "HTTP Error: %s" % e
|
@@ -43,7 +43,7 @@ def get_all_disapproved_ads(ad_group_id)
|
|
43
43
|
:predicates => [
|
44
44
|
{:field => 'AdGroupId', :operator => 'IN', :values => [ad_group_id]},
|
45
45
|
{
|
46
|
-
:field => '
|
46
|
+
:field => 'AdGroupCreativeApprovalStatus',
|
47
47
|
:operator => 'IN',
|
48
48
|
:values => ['DISAPPROVED']
|
49
49
|
}
|
@@ -68,12 +68,20 @@ def get_all_disapproved_ads(ad_group_id)
|
|
68
68
|
end
|
69
69
|
|
70
70
|
if __FILE__ == $0
|
71
|
-
API_VERSION = :
|
71
|
+
API_VERSION = :v201306
|
72
72
|
|
73
73
|
begin
|
74
74
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
75
75
|
get_all_disapproved_ads(ad_group_id)
|
76
76
|
|
77
|
+
# Authorization error.
|
78
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
79
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
80
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
81
|
+
"to retrieve and store OAuth2 tokens."
|
82
|
+
puts "See this wiki page for more details:\n\n " +
|
83
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
84
|
+
|
77
85
|
# HTTP errors.
|
78
86
|
rescue AdsCommon::Errors::HttpError => e
|
79
87
|
puts "HTTP Error: %s" % e
|
@@ -93,12 +93,20 @@ def handle_partial_failures(ad_group_id)
|
|
93
93
|
end
|
94
94
|
|
95
95
|
if __FILE__ == $0
|
96
|
-
API_VERSION = :
|
96
|
+
API_VERSION = :v201306
|
97
97
|
|
98
98
|
begin
|
99
99
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
100
100
|
handle_partial_failures(ad_group_id)
|
101
101
|
|
102
|
+
# Authorization error.
|
103
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
104
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
105
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
106
|
+
"to retrieve and store OAuth2 tokens."
|
107
|
+
puts "See this wiki page for more details:\n\n " +
|
108
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
109
|
+
|
102
110
|
# HTTP errors.
|
103
111
|
rescue AdsCommon::Errors::HttpError => e
|
104
112
|
puts "HTTP Error: %s" % e
|
@@ -114,12 +114,20 @@ def handle_policy_violation_error(ad_group_id)
|
|
114
114
|
end
|
115
115
|
|
116
116
|
if __FILE__ == $0
|
117
|
-
API_VERSION = :
|
117
|
+
API_VERSION = :v201306
|
118
118
|
|
119
119
|
begin
|
120
120
|
ad_group_id = 'INSERT_AD_GROUP_ID_HERE'.to_i
|
121
121
|
handle_policy_violation_error(ad_group_id)
|
122
122
|
|
123
|
+
# Authorization error.
|
124
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
125
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
126
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
127
|
+
"to retrieve and store OAuth2 tokens."
|
128
|
+
puts "See this wiki page for more details:\n\n " +
|
129
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
130
|
+
|
123
131
|
# HTTP errors.
|
124
132
|
rescue AdsCommon::Errors::HttpError => e
|
125
133
|
puts "HTTP Error: %s" % e
|
@@ -29,7 +29,8 @@ def handle_two_factor_authorization_error()
|
|
29
29
|
:method => 'ClientLogin',
|
30
30
|
:email => '2steptester@gmail.com',
|
31
31
|
:password => 'testaccount',
|
32
|
-
:user_agent => 'Ruby 2 Factor Sample'
|
32
|
+
:user_agent => 'Ruby 2 Factor Sample',
|
33
|
+
:developer_token => 'qwerty'
|
33
34
|
},
|
34
35
|
:service => {
|
35
36
|
:environment => 'PRODUCTION'
|
@@ -64,7 +65,7 @@ def handle_two_factor_authorization_error()
|
|
64
65
|
end
|
65
66
|
|
66
67
|
if __FILE__ == $0
|
67
|
-
API_VERSION = :
|
68
|
+
API_VERSION = :v201306
|
68
69
|
|
69
70
|
begin
|
70
71
|
handle_two_factor_authorization_error()
|
@@ -25,7 +25,6 @@
|
|
25
25
|
# Tags: MediaService.get
|
26
26
|
|
27
27
|
require 'adwords_api'
|
28
|
-
require 'adwords_api/utils'
|
29
28
|
|
30
29
|
def get_all_images_and_videos()
|
31
30
|
# AdwordsApi::Api will read a config file from ENV['HOME']/adwords_api.yml
|
@@ -60,10 +59,10 @@ def get_all_images_and_videos()
|
|
60
59
|
page = media_srv.get(selector)
|
61
60
|
if page[:entries]
|
62
61
|
page[:entries].each do |entry|
|
63
|
-
|
62
|
+
full_dimensions = entry[:dimensions]['FULL']
|
64
63
|
puts "Entry ID %d with dimensions %dx%d and MIME type is '%s'" %
|
65
|
-
[entry[:media_id],
|
66
|
-
|
64
|
+
[entry[:media_id], full_dimensions[:height],
|
65
|
+
full_dimensions[:width], entry[:mime_type]]
|
67
66
|
end
|
68
67
|
# Increment values to request the next page.
|
69
68
|
offset += PAGE_SIZE
|
@@ -77,12 +76,20 @@ def get_all_images_and_videos()
|
|
77
76
|
end
|
78
77
|
|
79
78
|
if __FILE__ == $0
|
80
|
-
API_VERSION = :
|
79
|
+
API_VERSION = :v201306
|
81
80
|
PAGE_SIZE = 500
|
82
81
|
|
83
82
|
begin
|
84
83
|
get_all_images_and_videos()
|
85
84
|
|
85
|
+
# Authorization error.
|
86
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
87
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
88
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
89
|
+
"to retrieve and store OAuth2 tokens."
|
90
|
+
puts "See this wiki page for more details:\n\n " +
|
91
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
92
|
+
|
86
93
|
# HTTP errors.
|
87
94
|
rescue AdsCommon::Errors::HttpError => e
|
88
95
|
puts "HTTP Error: %s" % e
|
@@ -0,0 +1,88 @@
|
|
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 set up OAuth2.0 authentication credentials.
|
22
|
+
#
|
23
|
+
# Tags: CampaignService.get
|
24
|
+
|
25
|
+
require 'adwords_api'
|
26
|
+
|
27
|
+
def setup_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
|
+
if token
|
46
|
+
print "\nWould you like to update your adwords_api.yml to save " +
|
47
|
+
"OAuth2 crdentials? (y/N): "
|
48
|
+
response = gets.chomp
|
49
|
+
if ('y'.casecmp(response) == 0) or ('yes'.casecmp(response) == 0)
|
50
|
+
adwords.save_oauth2_token(token)
|
51
|
+
puts 'OAuth2 token is now saved to ~/adwords_api.yml and will be ' +
|
52
|
+
'automatically used by the library.'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# Alternatively, you can provide one within the parameters:
|
57
|
+
#token = adwords.authorize({:oauth2_verification_code => verification_code})
|
58
|
+
|
59
|
+
# Note, 'token' is a Hash. Its value is not used in this example. If you need
|
60
|
+
# to be able to access the API in offline mode, with no user present, you
|
61
|
+
# should persist it to be used in subsequent invocations like this:
|
62
|
+
#adwords.authorize({:oauth2_token => token})
|
63
|
+
|
64
|
+
# No exception thrown - we are good to make a request.
|
65
|
+
end
|
66
|
+
|
67
|
+
if __FILE__ == $0
|
68
|
+
API_VERSION = :v201306
|
69
|
+
|
70
|
+
begin
|
71
|
+
setup_oauth2()
|
72
|
+
|
73
|
+
# HTTP errors.
|
74
|
+
rescue AdsCommon::Errors::HttpError => e
|
75
|
+
puts "HTTP Error: %s" % e
|
76
|
+
|
77
|
+
# API errors.
|
78
|
+
rescue AdwordsApi::Errors::ApiException => e
|
79
|
+
puts "Message: %s" % e.message
|
80
|
+
puts 'Errors:'
|
81
|
+
e.errors.each_with_index do |error, index|
|
82
|
+
puts "\tError [%d]:" % (index + 1)
|
83
|
+
error.each do |field, value|
|
84
|
+
puts "\t\t%s: %s" % [field, value]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# Encoding: utf-8
|
3
3
|
#
|
4
|
-
# Author:: api.
|
4
|
+
# Author:: api.dklimkin@gmail.com (Danial Klimkin)
|
5
5
|
#
|
6
6
|
# Copyright:: Copyright 2011, Google Inc. All Rights Reserved.
|
7
7
|
#
|
@@ -18,13 +18,11 @@
|
|
18
18
|
# See the License for the specific language governing permissions and
|
19
19
|
# limitations under the License.
|
20
20
|
#
|
21
|
-
# This example uploads an image. To get images, run
|
22
|
-
# get_all_images_and_videos.rb.
|
21
|
+
# This example uploads an image. To get images, run get_all_images.rb.
|
23
22
|
#
|
24
23
|
# Tags: MediaService.upload
|
25
24
|
|
26
25
|
require 'adwords_api'
|
27
|
-
require 'adwords_api/utils'
|
28
26
|
require 'base64'
|
29
27
|
|
30
28
|
def upload_image()
|
@@ -56,19 +54,31 @@ def upload_image()
|
|
56
54
|
|
57
55
|
# Upload image.
|
58
56
|
response = media_srv.upload([image])
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
57
|
+
if response and !response.empty?
|
58
|
+
ret_image = response.first
|
59
|
+
full_dimensions = ret_image[:dimensions]['FULL']
|
60
|
+
puts ("Image with ID %d, dimensions %dx%d and MIME type '%s' uploaded " +
|
61
|
+
"successfully.") % [ret_image[:media_id], full_dimensions[:height],
|
62
|
+
full_dimensions[:width], ret_image[:mime_type]]
|
63
|
+
else
|
64
|
+
puts 'No images uploaded.'
|
65
|
+
end
|
64
66
|
end
|
65
67
|
|
66
68
|
if __FILE__ == $0
|
67
|
-
API_VERSION = :
|
69
|
+
API_VERSION = :v201306
|
68
70
|
|
69
71
|
begin
|
70
72
|
upload_image()
|
71
73
|
|
74
|
+
# Authorization error.
|
75
|
+
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
|
76
|
+
puts "Authorization credentials are not valid. Edit adwords_api.yml for " +
|
77
|
+
"OAuth2 client ID and secret and run misc/setup_oauth2.rb example " +
|
78
|
+
"to retrieve and store OAuth2 tokens."
|
79
|
+
puts "See this wiki page for more details:\n\n " +
|
80
|
+
'http://code.google.com/p/google-api-ads-ruby/wiki/OAuth2'
|
81
|
+
|
72
82
|
# HTTP errors.
|
73
83
|
rescue AdsCommon::Errors::HttpError => e
|
74
84
|
puts "HTTP Error: %s" % e
|