| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# Copyright 2011, Google Inc. All Rights Reserved. |
|
2
|
|
|
|
|
|
|
# |
|
3
|
|
|
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
4
|
|
|
|
|
|
|
# you may not use this file except in compliance with the License. |
|
5
|
|
|
|
|
|
|
# You may obtain a copy of the License at |
|
6
|
|
|
|
|
|
|
# |
|
7
|
|
|
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
# Unless required by applicable law or agreed to in writing, software |
|
10
|
|
|
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
|
11
|
|
|
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
12
|
|
|
|
|
|
|
# See the License for the specific language governing permissions and |
|
13
|
|
|
|
|
|
|
# limitations under the License. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
package Google::Ads::AdWords::Client; |
|
16
|
|
|
|
|
|
|
|
|
17
|
12
|
|
|
12
|
|
626642
|
use strict; |
|
|
12
|
|
|
|
|
27
|
|
|
|
12
|
|
|
|
|
340
|
|
|
18
|
12
|
|
|
12
|
|
2676
|
use version; |
|
|
12
|
|
|
|
|
17896
|
|
|
|
12
|
|
|
|
|
81
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = qv("4.16.0"); |
|
20
|
|
|
|
|
|
|
|
|
21
|
12
|
|
|
12
|
|
4838
|
use Google::Ads::AdWords::Constants; |
|
|
12
|
|
|
|
|
32
|
|
|
|
12
|
|
|
|
|
362
|
|
|
22
|
12
|
|
|
12
|
|
3894
|
use Google::Ads::AdWords::Deserializer; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Google::Ads::AdWords::OAuth2ApplicationsHandler; |
|
24
|
|
|
|
|
|
|
use Google::Ads::AdWords::OAuth2ServiceAccountsHandler; |
|
25
|
|
|
|
|
|
|
use Google::Ads::AdWords::Reports::ReportingConfiguration; |
|
26
|
|
|
|
|
|
|
use Google::Ads::AdWords::Serializer; |
|
27
|
|
|
|
|
|
|
use Google::Ads::Common::HTTPTransport; |
|
28
|
|
|
|
|
|
|
use Google::Ads::Common::Utilities::AdsUtilityRegistry; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
use Class::Std::Fast; |
|
31
|
|
|
|
|
|
|
use SOAP::WSDL qv("2.00.10"); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
use constant OAUTH_2_APPLICATIONS_HANDLER => "OAUTH_2_APPLICATIONS_HANDLER"; |
|
34
|
|
|
|
|
|
|
use constant OAUTH_2_SERVICE_ACCOUNTS_HANDLER => |
|
35
|
|
|
|
|
|
|
"OAUTH_2_SERVICE_ACCOUNTS_HANDLER"; |
|
36
|
|
|
|
|
|
|
use constant AUTH_HANDLERS_ORDER => |
|
37
|
|
|
|
|
|
|
(OAUTH_2_APPLICATIONS_HANDLER, OAUTH_2_SERVICE_ACCOUNTS_HANDLER); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Class::Std-style attributes. Most values read from adwords.properties file. |
|
40
|
|
|
|
|
|
|
# These need to go in the same line for older Perl interpreters to understand. |
|
41
|
|
|
|
|
|
|
my %client_id_of : ATTR(:name :default<>); |
|
42
|
|
|
|
|
|
|
my %user_agent_of : ATTR(:name :default<>); |
|
43
|
|
|
|
|
|
|
my %developer_token_of : ATTR(:name :default<>); |
|
44
|
|
|
|
|
|
|
my %version_of : ATTR(:name :default<>); |
|
45
|
|
|
|
|
|
|
my %alternate_url_of : ATTR(:name :default<>); |
|
46
|
|
|
|
|
|
|
my %die_on_faults_of : ATTR(:name :default<0>); |
|
47
|
|
|
|
|
|
|
my %validate_only_of : ATTR(:name :default<0>); |
|
48
|
|
|
|
|
|
|
my %partial_failure_of : ATTR(:name :default<0>); |
|
49
|
|
|
|
|
|
|
my %reporting_config_of : ATTR(:name :default<>); |
|
50
|
|
|
|
|
|
|
my %include_utilities_of : ATTR(:name :default<>); |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
my %properties_file_of : ATTR(:init_arg :default<>); |
|
53
|
|
|
|
|
|
|
my %services_of : ATTR(:name :default<{}>); |
|
54
|
|
|
|
|
|
|
my %transport_of : ATTR(:name :default<>); |
|
55
|
|
|
|
|
|
|
my %auth_handlers_of : ATTR(:name :default<>); |
|
56
|
|
|
|
|
|
|
my %__enabled_auth_handler_of : ATTR(:name<__enabled_auth_handler> :default<>); |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Runtime statistics. |
|
59
|
|
|
|
|
|
|
my %requests_count_of : ATTR(:name :default<0>); |
|
60
|
|
|
|
|
|
|
my %failed_requests_count_of : ATTR(:name :default<0>); |
|
61
|
|
|
|
|
|
|
my %operations_count_of : ATTR(:name :default<0>); |
|
62
|
|
|
|
|
|
|
my %last_request_stats_of : ATTR(:name :default<>); |
|
63
|
|
|
|
|
|
|
my %last_soap_request_of : ATTR(:name :default<>); |
|
64
|
|
|
|
|
|
|
my %last_soap_response_of : ATTR(:name :default<>); |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Static module-level variables. |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# Automatically called by Class::Std after the values for all the attributes |
|
69
|
|
|
|
|
|
|
# have been populated but before the constuctor returns the new object. |
|
70
|
|
|
|
|
|
|
sub START { |
|
71
|
|
|
|
|
|
|
my ($self, $ident) = @_; |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $default_properties_file = |
|
74
|
|
|
|
|
|
|
Google::Ads::AdWords::Constants::DEFAULT_PROPERTIES_FILE; |
|
75
|
|
|
|
|
|
|
if (not $properties_file_of{$ident} and -e $default_properties_file) { |
|
76
|
|
|
|
|
|
|
$properties_file_of{$ident} = $default_properties_file; |
|
77
|
|
|
|
|
|
|
} |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my %properties = (); |
|
80
|
|
|
|
|
|
|
if ($properties_file_of{$ident}) { |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# If there's a valid properties file to read from, parse it and use the |
|
83
|
|
|
|
|
|
|
# config values to fill in any missing attributes. |
|
84
|
|
|
|
|
|
|
%properties = __parse_properties_file($properties_file_of{$ident}); |
|
85
|
|
|
|
|
|
|
$client_id_of{$ident} ||= $properties{clientId}; |
|
86
|
|
|
|
|
|
|
$user_agent_of{$ident} ||= $properties{useragent} || $properties{userAgent}; |
|
87
|
|
|
|
|
|
|
$developer_token_of{$ident} ||= $properties{developerToken}; |
|
88
|
|
|
|
|
|
|
$version_of{$ident} ||= $properties{version}; |
|
89
|
|
|
|
|
|
|
$alternate_url_of{$ident} ||= $properties{alternateUrl}; |
|
90
|
|
|
|
|
|
|
$validate_only_of{$ident} ||= $properties{validateOnly}; |
|
91
|
|
|
|
|
|
|
$partial_failure_of{$ident} ||= $properties{partialFailure}; |
|
92
|
|
|
|
|
|
|
$include_utilities_of{$ident} ||= |
|
93
|
|
|
|
|
|
|
$properties{"header.userAgent.includeUtilities"}; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# Construct the ReportingConfiguration. |
|
96
|
|
|
|
|
|
|
$reporting_config_of{$ident} ||= |
|
97
|
|
|
|
|
|
|
Google::Ads::AdWords::Reports::ReportingConfiguration->new({ |
|
98
|
|
|
|
|
|
|
skip_header => $properties{"reporting.skipHeader"}, |
|
99
|
|
|
|
|
|
|
skip_column_header => $properties{"reporting.skipColumnHeader"}, |
|
100
|
|
|
|
|
|
|
skip_summary => $properties{"reporting.skipSummary"}, |
|
101
|
|
|
|
|
|
|
include_zero_impressions => |
|
102
|
|
|
|
|
|
|
$properties{"reporting.includeZeroImpressions"}, |
|
103
|
|
|
|
|
|
|
use_raw_enum_values => $properties{"reporting.useRawEnumValues"}}); |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# SSL Peer validation setup. |
|
106
|
|
|
|
|
|
|
$self->__setup_SSL($properties{CAPath}, $properties{CAFile}); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# We want to provide default values for these attributes if they weren't |
|
110
|
|
|
|
|
|
|
# set by parameters to new() or the properties file. |
|
111
|
|
|
|
|
|
|
$alternate_url_of{$ident} ||= |
|
112
|
|
|
|
|
|
|
Google::Ads::AdWords::Constants::DEFAULT_ALTERNATE_URL; |
|
113
|
|
|
|
|
|
|
$validate_only_of{$ident} ||= |
|
114
|
|
|
|
|
|
|
Google::Ads::AdWords::Constants::DEFAULT_VALIDATE_ONLY; |
|
115
|
|
|
|
|
|
|
$version_of{$ident} ||= Google::Ads::AdWords::Constants::DEFAULT_VERSION; |
|
116
|
|
|
|
|
|
|
$partial_failure_of{$ident} ||= 0; |
|
117
|
|
|
|
|
|
|
$reporting_config_of{$ident} ||= |
|
118
|
|
|
|
|
|
|
Google::Ads::AdWords::Reports::ReportingConfiguration->new(); |
|
119
|
|
|
|
|
|
|
$include_utilities_of{$ident} = 1 |
|
120
|
|
|
|
|
|
|
unless defined $include_utilities_of{$ident}; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# Setup of auth handlers |
|
123
|
|
|
|
|
|
|
my %auth_handlers = (); |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
my $auth_handler = Google::Ads::AdWords::OAuth2ApplicationsHandler->new(); |
|
126
|
|
|
|
|
|
|
$auth_handler->initialize($self, \%properties); |
|
127
|
|
|
|
|
|
|
$auth_handlers{OAUTH_2_APPLICATIONS_HANDLER} = $auth_handler; |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
$auth_handler = Google::Ads::AdWords::OAuth2ServiceAccountsHandler->new(); |
|
130
|
|
|
|
|
|
|
$auth_handler->initialize($self, \%properties); |
|
131
|
|
|
|
|
|
|
$auth_handlers{OAUTH_2_SERVICE_ACCOUNTS_HANDLER} = $auth_handler; |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
$auth_handlers_of{$ident} = \%auth_handlers; |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Setups the HTTP transport and OAuthHandler this client will use. |
|
136
|
|
|
|
|
|
|
$transport_of{$ident} = Google::Ads::Common::HTTPTransport->new(); |
|
137
|
|
|
|
|
|
|
$transport_of{$ident}->client($self); |
|
138
|
|
|
|
|
|
|
} |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
# Automatically called by Class::Std when an unknown method is invoked on an |
|
141
|
|
|
|
|
|
|
# instance of this class. It is used to handle creating singletons (local to |
|
142
|
|
|
|
|
|
|
# each Google::Ads::AdWords::Client instance) of all the SOAP services. The |
|
143
|
|
|
|
|
|
|
# names of the services may change and shouldn't be hardcoded. |
|
144
|
|
|
|
|
|
|
sub AUTOMETHOD { |
|
145
|
|
|
|
|
|
|
my ($self, $ident) = @_; |
|
146
|
|
|
|
|
|
|
my $method_name = $_; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
# All SOAP services should end in "Service"; fail early if the requested |
|
149
|
|
|
|
|
|
|
# method doesn't. |
|
150
|
|
|
|
|
|
|
if ($method_name =~ /^\w+Service$/) { |
|
151
|
|
|
|
|
|
|
if ($self->get_services()->{$method_name}) { |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# To emulate a singleton, return the existing instance of the service if |
|
154
|
|
|
|
|
|
|
# we already have it. The return value of AUTOMETHOD must be a sub |
|
155
|
|
|
|
|
|
|
# reference which is then invoked, so wrap the service in sub { }. |
|
156
|
|
|
|
|
|
|
return sub { |
|
157
|
|
|
|
|
|
|
return $self->get_services()->{$method_name}; |
|
158
|
|
|
|
|
|
|
}; |
|
159
|
|
|
|
|
|
|
} else { |
|
160
|
|
|
|
|
|
|
my $version = $self->get_version(); |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Check to see if there is a module with that name under |
|
163
|
|
|
|
|
|
|
# Google::Ads::AdWords::$version if not we warn and return nothing. |
|
164
|
|
|
|
|
|
|
my $module_name = |
|
165
|
|
|
|
|
|
|
"Google::Ads::AdWords::${version}::${method_name}" . |
|
166
|
|
|
|
|
|
|
"::${method_name}InterfacePort"; |
|
167
|
|
|
|
|
|
|
eval("require $module_name"); |
|
168
|
|
|
|
|
|
|
if ($@) { |
|
169
|
|
|
|
|
|
|
warn("Module $module_name was not found."); |
|
170
|
|
|
|
|
|
|
return; |
|
171
|
|
|
|
|
|
|
} else { |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
# Generating the service endpoint url of the form |
|
174
|
|
|
|
|
|
|
# https://{server_url}/{group_name(cm/job/info/o)}/{version}/{service}. |
|
175
|
|
|
|
|
|
|
my $server_url = |
|
176
|
|
|
|
|
|
|
$self->get_alternate_url() =~ /\/$/ |
|
177
|
|
|
|
|
|
|
? substr($self->get_alternate_url(), 0, -1) |
|
178
|
|
|
|
|
|
|
: $self->get_alternate_url(); |
|
179
|
|
|
|
|
|
|
my $service_to_group_name = |
|
180
|
|
|
|
|
|
|
$Google::Ads::AdWords::Constants::SERVICE_TO_GROUP{$method_name}; |
|
181
|
|
|
|
|
|
|
if (!$service_to_group_name) { |
|
182
|
|
|
|
|
|
|
die("Service " . $method_name . " is not configured in the library."); |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
my $endpoint_url = |
|
185
|
|
|
|
|
|
|
sprintf(Google::Ads::AdWords::Constants::PROXY_FORMAT_STRING, |
|
186
|
|
|
|
|
|
|
$server_url, $service_to_group_name, $self->get_version(), |
|
187
|
|
|
|
|
|
|
$method_name); |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# If a suitable module is found, instantiate it and store it in |
|
190
|
|
|
|
|
|
|
# instance-specific storage to emulate a singleton. |
|
191
|
|
|
|
|
|
|
my $service_port = $module_name->new({ |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
# Setting the server endpoint of the service. |
|
194
|
|
|
|
|
|
|
proxy => [$endpoint_url], |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
# Associating our custom serializer. |
|
197
|
|
|
|
|
|
|
serializer => |
|
198
|
|
|
|
|
|
|
Google::Ads::AdWords::Serializer->new({client => $self}), |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# Associating our custom deserializer. |
|
201
|
|
|
|
|
|
|
deserializer => |
|
202
|
|
|
|
|
|
|
Google::Ads::AdWords::Deserializer->new({client => $self})}); |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Injecting our own transport. |
|
205
|
|
|
|
|
|
|
$service_port->set_transport($self->get_transport()); |
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
if ($ENV{HTTP_PROXY}) { |
|
208
|
|
|
|
|
|
|
$service_port->get_transport()->proxy(['http'], $ENV{HTTP_PROXY}); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
|
|
|
|
|
|
if ($ENV{HTTPS_PROXY}) { |
|
211
|
|
|
|
|
|
|
$service_port->get_transport()->proxy(['https'], $ENV{HTTPS_PROXY}); |
|
212
|
|
|
|
|
|
|
} |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
$self->get_services()->{$method_name} = $service_port; |
|
215
|
|
|
|
|
|
|
return sub { |
|
216
|
|
|
|
|
|
|
return $self->get_services()->{$method_name}; |
|
217
|
|
|
|
|
|
|
}; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
} |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
# Protected method to retrieve the proper enabled authorization handler. |
|
224
|
|
|
|
|
|
|
sub _get_auth_handler { |
|
225
|
|
|
|
|
|
|
my $self = shift; |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
# Check if we have cached the enabled auth_handler. |
|
228
|
|
|
|
|
|
|
if ($self->get___enabled_auth_handler()) { |
|
229
|
|
|
|
|
|
|
return $self->get___enabled_auth_handler(); |
|
230
|
|
|
|
|
|
|
} |
|
231
|
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
my $auth_handlers = $self->get_auth_handlers(); |
|
233
|
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
foreach my $handler_id (AUTH_HANDLERS_ORDER) { |
|
235
|
|
|
|
|
|
|
if ($auth_handlers->{$handler_id}->is_auth_enabled()) { |
|
236
|
|
|
|
|
|
|
$self->set___enabled_auth_handler($auth_handlers->{$handler_id}); |
|
237
|
|
|
|
|
|
|
last; |
|
238
|
|
|
|
|
|
|
} |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
return $self->get___enabled_auth_handler(); |
|
242
|
|
|
|
|
|
|
} |
|
243
|
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
# Private method to setup IO::Socket::SSL and Crypt::SSLeay variables |
|
245
|
|
|
|
|
|
|
# for certificate and hostname validation. |
|
246
|
|
|
|
|
|
|
sub __setup_SSL { |
|
247
|
|
|
|
|
|
|
my ($self, $ca_path, $ca_file) = @_; |
|
248
|
|
|
|
|
|
|
if ($ca_path || $ca_file) { |
|
249
|
|
|
|
|
|
|
$ENV{HTTPS_CA_DIR} = $ca_path; |
|
250
|
|
|
|
|
|
|
$ENV{HTTPS_CA_FILE} = $ca_file; |
|
251
|
|
|
|
|
|
|
eval { |
|
252
|
|
|
|
|
|
|
require IO::Socket::SSL; |
|
253
|
|
|
|
|
|
|
require Net::SSLeay; |
|
254
|
|
|
|
|
|
|
IO::Socket::SSL::set_ctx_defaults( |
|
255
|
|
|
|
|
|
|
verify_mode => Net::SSLeay->VERIFY_PEER(), |
|
256
|
|
|
|
|
|
|
SSL_verifycn_scheme => "www", |
|
257
|
|
|
|
|
|
|
ca_file => $ca_file, |
|
258
|
|
|
|
|
|
|
ca_path => $ca_path |
|
259
|
|
|
|
|
|
|
); |
|
260
|
|
|
|
|
|
|
}; |
|
261
|
|
|
|
|
|
|
} |
|
262
|
|
|
|
|
|
|
} |
|
263
|
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
# Private method to parse values in a properties file. |
|
265
|
|
|
|
|
|
|
sub __parse_properties_file { |
|
266
|
|
|
|
|
|
|
my ($properties_file) = @_; |
|
267
|
|
|
|
|
|
|
my %properties; |
|
268
|
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
# glob() to expand any metacharacters. |
|
270
|
|
|
|
|
|
|
($properties_file) = glob($properties_file); |
|
271
|
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
if (open(PROP_FILE, $properties_file)) { |
|
273
|
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
# The data in the file should be in the following format: |
|
275
|
|
|
|
|
|
|
# key1=value1 |
|
276
|
|
|
|
|
|
|
# key2=value2 |
|
277
|
|
|
|
|
|
|
while (my $line = ) { |
|
278
|
|
|
|
|
|
|
chomp($line); |
|
279
|
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
# Skip comments. |
|
281
|
|
|
|
|
|
|
next if ($line =~ /^#/ || $line =~ /^\s*$/); |
|
282
|
|
|
|
|
|
|
my ($key, $value) = split(/=/, $line, 2); |
|
283
|
|
|
|
|
|
|
$properties{$key} = $value; |
|
284
|
|
|
|
|
|
|
} |
|
285
|
|
|
|
|
|
|
close(PROP_FILE); |
|
286
|
|
|
|
|
|
|
} else { |
|
287
|
|
|
|
|
|
|
die("Couldn't open properties file $properties_file for reading: $!\n"); |
|
288
|
|
|
|
|
|
|
} |
|
289
|
|
|
|
|
|
|
return %properties; |
|
290
|
|
|
|
|
|
|
} |
|
291
|
|
|
|
|
|
|
|
|
292
|
|
|
|
|
|
|
# Protected method to generate the appropriate SOAP request header. |
|
293
|
|
|
|
|
|
|
sub _get_header { |
|
294
|
|
|
|
|
|
|
my ($self) = @_; |
|
295
|
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
# A value of 1 (evaluating to true) occurs when a user explicitly defines 1 |
|
297
|
|
|
|
|
|
|
# in the properties file or a user has ommitted the value from the properties |
|
298
|
|
|
|
|
|
|
# file. A value of 0 (evaluating to false) occurs when a user explicitly |
|
299
|
|
|
|
|
|
|
# defines 0 in the properties file. |
|
300
|
|
|
|
|
|
|
my $ads_utilities = |
|
301
|
|
|
|
|
|
|
($self->get_include_utilities()) |
|
302
|
|
|
|
|
|
|
? sprintf( |
|
303
|
|
|
|
|
|
|
", %s", |
|
304
|
|
|
|
|
|
|
Google::Ads::Common::Utilities::AdsUtilityRegistry |
|
305
|
|
|
|
|
|
|
->get_and_reset_ads_utility_registry_string( |
|
306
|
|
|
|
|
|
|
)) |
|
307
|
|
|
|
|
|
|
: ""; |
|
308
|
|
|
|
|
|
|
|
|
309
|
|
|
|
|
|
|
# Set the application name to the default if not provided. |
|
310
|
|
|
|
|
|
|
# Verify that it is ASCII. |
|
311
|
|
|
|
|
|
|
my $application_name = |
|
312
|
|
|
|
|
|
|
($self->get_user_agent() |
|
313
|
|
|
|
|
|
|
&& ($self->get_user_agent() ne "INSERT_USER_AGENT_HERE") |
|
314
|
|
|
|
|
|
|
? $self->get_user_agent() |
|
315
|
|
|
|
|
|
|
: Google::Ads::AdWords::Constants::DEFAULT_USER_AGENT); |
|
316
|
|
|
|
|
|
|
if ($application_name =~ /[[:^ascii:]]/) { |
|
317
|
|
|
|
|
|
|
my $error_message = sprintf( |
|
318
|
|
|
|
|
|
|
"userAgent [%s] in client must be ASCII.", $application_name); |
|
319
|
|
|
|
|
|
|
if ($self->get_die_on_faults()) { |
|
320
|
|
|
|
|
|
|
die($error_message); |
|
321
|
|
|
|
|
|
|
} else { |
|
322
|
|
|
|
|
|
|
warn($error_message); |
|
323
|
|
|
|
|
|
|
} |
|
324
|
|
|
|
|
|
|
} |
|
325
|
|
|
|
|
|
|
|
|
326
|
|
|
|
|
|
|
# Always prepend the module identifier to the user agent. |
|
327
|
|
|
|
|
|
|
my $user_agent = sprintf( |
|
328
|
|
|
|
|
|
|
"%s (AwApi-Perl/%s, Common-Perl/%s, SOAP-WSDL/%s, " . |
|
329
|
|
|
|
|
|
|
"libwww-perl/%s, perl/%s%s)", |
|
330
|
|
|
|
|
|
|
$application_name, |
|
331
|
|
|
|
|
|
|
${Google::Ads::AdWords::Constants::VERSION}, |
|
332
|
|
|
|
|
|
|
${Google::Ads::Common::Constants::VERSION}, |
|
333
|
|
|
|
|
|
|
${SOAP::WSDL::VERSION}, |
|
334
|
|
|
|
|
|
|
${LWP::UserAgent::VERSION}, |
|
335
|
|
|
|
|
|
|
$], |
|
336
|
|
|
|
|
|
|
$ads_utilities |
|
337
|
|
|
|
|
|
|
); |
|
338
|
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
my $headers = { |
|
340
|
|
|
|
|
|
|
userAgent => $user_agent, |
|
341
|
|
|
|
|
|
|
developerToken => $self->get_developer_token(), |
|
342
|
|
|
|
|
|
|
validateOnly => $self->get_validate_only(), |
|
343
|
|
|
|
|
|
|
partialFailure => $self->get_partial_failure()}; |
|
344
|
|
|
|
|
|
|
my $clientId = $self->get_client_id(); |
|
345
|
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
# $clientId may not be set, in which case we're operating on the account |
|
347
|
|
|
|
|
|
|
# specified by the auth credentials. |
|
348
|
|
|
|
|
|
|
if ($clientId) { |
|
349
|
|
|
|
|
|
|
$headers->{clientCustomerId} = $clientId; |
|
350
|
|
|
|
|
|
|
} |
|
351
|
|
|
|
|
|
|
|
|
352
|
|
|
|
|
|
|
return $headers; |
|
353
|
|
|
|
|
|
|
} |
|
354
|
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
sub get_oauth_2_handler { |
|
356
|
|
|
|
|
|
|
my ($self) = @_; |
|
357
|
|
|
|
|
|
|
|
|
358
|
|
|
|
|
|
|
return $self->get_auth_handlers()->{OAUTH_2_APPLICATIONS_HANDLER}; |
|
359
|
|
|
|
|
|
|
} |
|
360
|
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
sub get_oauth_2_applications_handler { |
|
362
|
|
|
|
|
|
|
my ($self) = @_; |
|
363
|
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
return $self->get_auth_handlers()->{OAUTH_2_APPLICATIONS_HANDLER}; |
|
365
|
|
|
|
|
|
|
} |
|
366
|
|
|
|
|
|
|
|
|
367
|
|
|
|
|
|
|
sub get_oauth_2_service_accounts_handler { |
|
368
|
|
|
|
|
|
|
my ($self) = @_; |
|
369
|
|
|
|
|
|
|
|
|
370
|
|
|
|
|
|
|
return $self->get_auth_handlers()->{OAUTH_2_SERVICE_ACCOUNTS_HANDLER}; |
|
371
|
|
|
|
|
|
|
} |
|
372
|
|
|
|
|
|
|
|
|
373
|
|
|
|
|
|
|
# Adds a new RequestStats object to the client and updates the aggregated |
|
374
|
|
|
|
|
|
|
# stats. It also checks against the MAX_NUM_OF_REQUEST_STATS constant to |
|
375
|
|
|
|
|
|
|
# not make the array of lastest stats grow infinitely. |
|
376
|
|
|
|
|
|
|
sub _push_new_request_stats { |
|
377
|
|
|
|
|
|
|
my ($self, $request_stats) = @_; |
|
378
|
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
$self->set_last_request_stats($request_stats); |
|
380
|
|
|
|
|
|
|
$self->set_requests_count($self->get_requests_count() + 1); |
|
381
|
|
|
|
|
|
|
$request_stats->get_is_fault() |
|
382
|
|
|
|
|
|
|
and |
|
383
|
|
|
|
|
|
|
$self->set_failed_requests_count($self->get_failed_requests_count() + 1); |
|
384
|
|
|
|
|
|
|
$self->set_operations_count( |
|
385
|
|
|
|
|
|
|
$self->get_operations_count() + $request_stats->get_operations()); |
|
386
|
|
|
|
|
|
|
} |
|
387
|
|
|
|
|
|
|
|
|
388
|
|
|
|
|
|
|
1; |
|
389
|
|
|
|
|
|
|
|
|
390
|
|
|
|
|
|
|
=pod |
|
391
|
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
=head1 NAME |
|
393
|
|
|
|
|
|
|
|
|
394
|
|
|
|
|
|
|
Google::Ads::AdWords::Client |
|
395
|
|
|
|
|
|
|
|
|
396
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
397
|
|
|
|
|
|
|
|
|
398
|
|
|
|
|
|
|
use Google::Ads::AdWords::Client; |
|
399
|
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
my $client = Google::Ads::AdWords::Client->new(); |
|
401
|
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
my $adGroupId = "12345678"; |
|
403
|
|
|
|
|
|
|
|
|
404
|
|
|
|
|
|
|
my $adgroupad_selector = |
|
405
|
|
|
|
|
|
|
Google::Ads::AdWords::v201702::Types::AdGroupAdSelector->new({ |
|
406
|
|
|
|
|
|
|
adGroupIds => [$adGroupId] |
|
407
|
|
|
|
|
|
|
}); |
|
408
|
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
my $page = |
|
410
|
|
|
|
|
|
|
$client->AdGroupAdService()->get({selector => $adgroupad_selector}); |
|
411
|
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
if ($page->get_totalNumEntries() > 0) { |
|
413
|
|
|
|
|
|
|
foreach my $entry (@{$page->get_entries()}) { |
|
414
|
|
|
|
|
|
|
#Do something with the results |
|
415
|
|
|
|
|
|
|
} |
|
416
|
|
|
|
|
|
|
} else { |
|
417
|
|
|
|
|
|
|
print "No AdGroupAds found.\n"; |
|
418
|
|
|
|
|
|
|
} |
|
419
|
|
|
|
|
|
|
|
|
420
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
421
|
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
Google::Ads::AdWords::Client is the main interface to the AdWords API. It takes |
|
423
|
|
|
|
|
|
|
care of handling your API credentials, and exposes all of the underlying |
|
424
|
|
|
|
|
|
|
services that make up the AdWords API. |
|
425
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
|
|
Due to internal patching of the C module, the |
|
427
|
|
|
|
|
|
|
C module should be loaded before other |
|
428
|
|
|
|
|
|
|
C modules. A warning will occur if modules are loaded in the |
|
429
|
|
|
|
|
|
|
wrong order. |
|
430
|
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
432
|
|
|
|
|
|
|
|
|
433
|
|
|
|
|
|
|
Each of these attributes can be set via Google::Ads::AdWords::Client->new(). |
|
434
|
|
|
|
|
|
|
Alternatively, there is a get_ and set_ method associated with each attribute |
|
435
|
|
|
|
|
|
|
for retrieving or setting them dynamically. For example, the set_client_id() |
|
436
|
|
|
|
|
|
|
allows you to change the value of the client_id attribute and get_client_id() |
|
437
|
|
|
|
|
|
|
returns the current value of the attribute. |
|
438
|
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=head2 client_id |
|
440
|
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
An optional 10 digit client id (with or without dashes) to specify the AdWords |
|
442
|
|
|
|
|
|
|
account to act upon. |
|
443
|
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
=head2 user_agent |
|
445
|
|
|
|
|
|
|
|
|
446
|
|
|
|
|
|
|
A user-generated string used to identify your application. If nothing is |
|
447
|
|
|
|
|
|
|
specified, "unknown" will be used instead. |
|
448
|
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=head2 developer_token |
|
450
|
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
A string used to tie usage of the AdWords API to a specific AdWords manager |
|
452
|
|
|
|
|
|
|
account. |
|
453
|
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
The value should be a character string assigned to you by Google. You can |
|
455
|
|
|
|
|
|
|
apply for a Developer Token by following the instructions at |
|
456
|
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
https://developers.google.com/adwords/api/docs/signingup |
|
458
|
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
=head2 version |
|
460
|
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
The version of the AdWords API to use. Currently C is the default |
|
462
|
|
|
|
|
|
|
version. |
|
463
|
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
=head2 alternate_url |
|
465
|
|
|
|
|
|
|
|
|
466
|
|
|
|
|
|
|
The URL of an alternate AdWords API server to use. |
|
467
|
|
|
|
|
|
|
|
|
468
|
|
|
|
|
|
|
The default value is C |
|
469
|
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
=head2 validate_only |
|
471
|
|
|
|
|
|
|
|
|
472
|
|
|
|
|
|
|
If is set to "true" calls to services will only perform validation, the results |
|
473
|
|
|
|
|
|
|
will be either empty response or a SOAP fault with the API error causing the |
|
474
|
|
|
|
|
|
|
fault. |
|
475
|
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
The default is "false". |
|
477
|
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
=head2 partial_failure |
|
479
|
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
If true, API will try to commit as many error free operations as possible and |
|
481
|
|
|
|
|
|
|
report the other operations' errors. This flag is currently only supported by |
|
482
|
|
|
|
|
|
|
the AdGroupCriterionService. |
|
483
|
|
|
|
|
|
|
|
|
484
|
|
|
|
|
|
|
The default is "false". |
|
485
|
|
|
|
|
|
|
|
|
486
|
|
|
|
|
|
|
=head2 reporting_config |
|
487
|
|
|
|
|
|
|
|
|
488
|
|
|
|
|
|
|
The reporting configuration that controls additional options such as excluding |
|
489
|
|
|
|
|
|
|
the report header or summary row. Only supported starting with |
|
490
|
|
|
|
|
|
|
L. |
|
491
|
|
|
|
|
|
|
|
|
492
|
|
|
|
|
|
|
=head2 die_on_faults |
|
493
|
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
By default the client returns a L object |
|
495
|
|
|
|
|
|
|
if an error has ocurred at the server side, however if this flag is set to true, |
|
496
|
|
|
|
|
|
|
then the client will issue a die command on received SOAP faults. |
|
497
|
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
The default is "false". |
|
499
|
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
=head2 requests_count |
|
501
|
|
|
|
|
|
|
|
|
502
|
|
|
|
|
|
|
Number of requests performed with this client so far. |
|
503
|
|
|
|
|
|
|
|
|
504
|
|
|
|
|
|
|
=head2 failed_requests_count |
|
505
|
|
|
|
|
|
|
|
|
506
|
|
|
|
|
|
|
Number of failed requests performed with this client so far. |
|
507
|
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
=head2 operations_count |
|
509
|
|
|
|
|
|
|
|
|
510
|
|
|
|
|
|
|
Number of operations made with this client so far. |
|
511
|
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=head2 requests_stats |
|
513
|
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
An array of L containing the statistics of |
|
515
|
|
|
|
|
|
|
the last L requests. |
|
516
|
|
|
|
|
|
|
|
|
517
|
|
|
|
|
|
|
=head2 last_request_stats |
|
518
|
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
A L containing the statistics the last |
|
520
|
|
|
|
|
|
|
request performed by this client. |
|
521
|
|
|
|
|
|
|
|
|
522
|
|
|
|
|
|
|
=head2 last_soap_request |
|
523
|
|
|
|
|
|
|
|
|
524
|
|
|
|
|
|
|
A string containing the last SOAP request XML sent by this client. |
|
525
|
|
|
|
|
|
|
|
|
526
|
|
|
|
|
|
|
=head2 last_soap_response |
|
527
|
|
|
|
|
|
|
|
|
528
|
|
|
|
|
|
|
A string containing the last SOAP response XML sent by this client. |
|
529
|
|
|
|
|
|
|
|
|
530
|
|
|
|
|
|
|
=head1 METHODS |
|
531
|
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=head2 new |
|
533
|
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
Initializes a new Google::Ads::AdWords::Client object. |
|
535
|
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=head3 Parameters |
|
537
|
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
new() takes parameters as a hash reference. |
|
539
|
|
|
|
|
|
|
The attributes of this object can be populated in a number of ways: |
|
540
|
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
=over |
|
542
|
|
|
|
|
|
|
|
|
543
|
|
|
|
|
|
|
=item * |
|
544
|
|
|
|
|
|
|
|
|
545
|
|
|
|
|
|
|
If the properties_file parameter is given, then properties are read from the |
|
546
|
|
|
|
|
|
|
file at that path and the corresponding attributes are populated. |
|
547
|
|
|
|
|
|
|
|
|
548
|
|
|
|
|
|
|
=item * |
|
549
|
|
|
|
|
|
|
|
|
550
|
|
|
|
|
|
|
If no properties_file parameter is given, then the code checks to see if there |
|
551
|
|
|
|
|
|
|
is a file named "adwords.properties" in the home directory of the current user. |
|
552
|
|
|
|
|
|
|
If there is, then properties are read from there. |
|
553
|
|
|
|
|
|
|
|
|
554
|
|
|
|
|
|
|
=item * |
|
555
|
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
Any of the L can be passed in as keys in the parameters hash |
|
557
|
|
|
|
|
|
|
reference. If any attribute is explicitly passed in then it will override any |
|
558
|
|
|
|
|
|
|
value for that attribute that might be in a properties file. |
|
559
|
|
|
|
|
|
|
|
|
560
|
|
|
|
|
|
|
=back |
|
561
|
|
|
|
|
|
|
|
|
562
|
|
|
|
|
|
|
=head3 Returns |
|
563
|
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
A new Google::Ads::AdWords::Client object with the appropriate attributes set. |
|
565
|
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
=head3 Exceptions |
|
567
|
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
If a properties_file is passed in but the file cannot be read, the code will |
|
569
|
|
|
|
|
|
|
die() with an error message describing the failure. |
|
570
|
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
=head3 Example |
|
572
|
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
# Basic use case. Attributes will be read from ~/adwords.properties file. |
|
574
|
|
|
|
|
|
|
my $client = Google::Ads::AdWords::Client->new(); |
|
575
|
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
# Most attributes from a custom properties file, but override client_id. |
|
577
|
|
|
|
|
|
|
eval { |
|
578
|
|
|
|
|
|
|
my $client = Google::Ads::AdWords::Client->new({ |
|
579
|
|
|
|
|
|
|
properties_file => "/path/to/adwords.properties", |
|
580
|
|
|
|
|
|
|
client_id => "123-456-7890", |
|
581
|
|
|
|
|
|
|
}); |
|
582
|
|
|
|
|
|
|
}; |
|
583
|
|
|
|
|
|
|
if ($@) { |
|
584
|
|
|
|
|
|
|
# The properties file couldn't be read; handle error as appropriate. |
|
585
|
|
|
|
|
|
|
} |
|
586
|
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
# Specify all attributes explicitly. The properties file will not override. |
|
588
|
|
|
|
|
|
|
my $client = Google::Ads::AdWords::Client->new({ |
|
589
|
|
|
|
|
|
|
client_id => "123-456-7890", |
|
590
|
|
|
|
|
|
|
developer_token => "123xyzabc...", |
|
591
|
|
|
|
|
|
|
user_agent => "My Sample Program", |
|
592
|
|
|
|
|
|
|
}); |
|
593
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_refresh_token('1/Abc...'); |
|
594
|
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
=head2 set_die_on_faults |
|
596
|
|
|
|
|
|
|
|
|
597
|
|
|
|
|
|
|
This module supports two approaches to handling SOAP faults (i.e. errors |
|
598
|
|
|
|
|
|
|
returned by the underlying SOAP service). |
|
599
|
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
One approach is to issue a die() with a description of the error when a SOAP |
|
601
|
|
|
|
|
|
|
fault occurs. This die() would ideally be contained within an eval { }; block, |
|
602
|
|
|
|
|
|
|
thereby emulating try { } / catch { } exception functionality in other |
|
603
|
|
|
|
|
|
|
languages. |
|
604
|
|
|
|
|
|
|
|
|
605
|
|
|
|
|
|
|
A different approach is to require developers to explicitly check for SOAP |
|
606
|
|
|
|
|
|
|
faults being returned after each AdWords API method. This approach requires a |
|
607
|
|
|
|
|
|
|
bit more work, but has the advantage of exposing the full details of the SOAP |
|
608
|
|
|
|
|
|
|
fault, like the fault code. |
|
609
|
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
Refer to the object L for more detail on |
|
611
|
|
|
|
|
|
|
how faults get returned. |
|
612
|
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
The default value is false, i.e. you must explicitly check for faults. |
|
614
|
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
=head3 Parameters |
|
616
|
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
A true value will cause this module to die() when a SOAP fault occurs. |
|
618
|
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
A false value will supress this die(). This is the default behavior. |
|
620
|
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
=head3 Returns |
|
622
|
|
|
|
|
|
|
|
|
623
|
|
|
|
|
|
|
The input parameter is returned. |
|
624
|
|
|
|
|
|
|
|
|
625
|
|
|
|
|
|
|
=head3 Example |
|
626
|
|
|
|
|
|
|
|
|
627
|
|
|
|
|
|
|
# $client is a Google::Ads::AdWords::Client object. |
|
628
|
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
# Enable die()ing on faults. |
|
630
|
|
|
|
|
|
|
$client->set_die_on_faults(1); |
|
631
|
|
|
|
|
|
|
eval { |
|
632
|
|
|
|
|
|
|
my $response = $client->AdGroupAdService->mutate($mutate_params); |
|
633
|
|
|
|
|
|
|
}; |
|
634
|
|
|
|
|
|
|
if ($@) { |
|
635
|
|
|
|
|
|
|
# Do something with the error information in $@. |
|
636
|
|
|
|
|
|
|
} |
|
637
|
|
|
|
|
|
|
|
|
638
|
|
|
|
|
|
|
# Default behavior. |
|
639
|
|
|
|
|
|
|
$client->set_die_on_faults(0); |
|
640
|
|
|
|
|
|
|
my $response = $client->AdGroupAdService->mutate($mutate_params); |
|
641
|
|
|
|
|
|
|
if ($response->isa("SOAP::WSDL::SOAP::Typelib::Fault11")) { |
|
642
|
|
|
|
|
|
|
my $code = $response->get_faultcode() || ''; |
|
643
|
|
|
|
|
|
|
my $description = $response->get_faultstring() || ''; |
|
644
|
|
|
|
|
|
|
my $actor = $response->get_faultactor() || ''; |
|
645
|
|
|
|
|
|
|
my $detail = $response->get_faultdetail() || ''; |
|
646
|
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
# Do something with this error information. |
|
648
|
|
|
|
|
|
|
} |
|
649
|
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
=head2 get_die_on_faults |
|
651
|
|
|
|
|
|
|
|
|
652
|
|
|
|
|
|
|
=head3 Returns |
|
653
|
|
|
|
|
|
|
|
|
654
|
|
|
|
|
|
|
A true or false value indicating whether the Google::Ads::AdWords::Client |
|
655
|
|
|
|
|
|
|
instance is set to die() on SOAP faults. |
|
656
|
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
=head2 {ServiceName} |
|
658
|
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
The client object contains a method for every service provided by the API. |
|
660
|
|
|
|
|
|
|
So for example it can invoked as $client->AdGroupService() and it will return |
|
661
|
|
|
|
|
|
|
an object of type |
|
662
|
|
|
|
|
|
|
L |
|
663
|
|
|
|
|
|
|
when using version v201702 of the API. |
|
664
|
|
|
|
|
|
|
For a list of all available services please refer to |
|
665
|
|
|
|
|
|
|
http://developers.google.com/adwords/api/docs and for examples on |
|
666
|
|
|
|
|
|
|
how to invoke the services please refer to scripts in the examples folder. |
|
667
|
|
|
|
|
|
|
|
|
668
|
|
|
|
|
|
|
=head2 get_oauth_2_applications_handler |
|
669
|
|
|
|
|
|
|
|
|
670
|
|
|
|
|
|
|
Returns the OAuth2 for Web/Installed applications authorization handler |
|
671
|
|
|
|
|
|
|
attached to the client, for programmatically setting/overriding its properties. |
|
672
|
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_client_id('client-id'); |
|
674
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_client_secret('client-secret'); |
|
675
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_access_token('access-token'); |
|
676
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_refresh_token('refresh-token'); |
|
677
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_access_type('access-type'); |
|
678
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_prompt('prompt'); |
|
679
|
|
|
|
|
|
|
$client->get_oauth_2_applications_handler()->set_redirect_uri('redirect-url'); |
|
680
|
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
Refer to L for more details. |
|
682
|
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
=head2 get_oauth_2_service_accounts_handler |
|
684
|
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
Returns the OAuth2 authorization handler attached to the client, for |
|
686
|
|
|
|
|
|
|
programmatically setting/overriding its specific properties. |
|
687
|
|
|
|
|
|
|
|
|
688
|
|
|
|
|
|
|
$client->get_oauth_2_service_accounts_handler()->set_client_id('email'); |
|
689
|
|
|
|
|
|
|
$client->get_oauth_2_service_accounts_handler()->set_email_address('email'); |
|
690
|
|
|
|
|
|
|
$client->get_oauth_2_service_accounts_handler()-> |
|
691
|
|
|
|
|
|
|
set_delegated_email_address('delegated-email'); |
|
692
|
|
|
|
|
|
|
$client->get_oauth_2_service_accounts_handler()-> |
|
693
|
|
|
|
|
|
|
set_pem_file('path-to-certificate'); |
|
694
|
|
|
|
|
|
|
$client->get_oauth_2_service_accounts_handler()->set_display_name('email'); |
|
695
|
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
Refer to L for more details. |
|
697
|
|
|
|
|
|
|
|
|
698
|
|
|
|
|
|
|
=head2 __setup_SSL (Private) |
|
699
|
|
|
|
|
|
|
|
|
700
|
|
|
|
|
|
|
Setups IO::Socket::SSL and Crypt::SSLeay environment variables to work with |
|
701
|
|
|
|
|
|
|
SSL certificate validation. |
|
702
|
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
=head3 Parameters |
|
704
|
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
The path to the certificate authorites folder and the path to the certificate |
|
706
|
|
|
|
|
|
|
authorites file. Either can be null. |
|
707
|
|
|
|
|
|
|
|
|
708
|
|
|
|
|
|
|
=head3 Returns |
|
709
|
|
|
|
|
|
|
|
|
710
|
|
|
|
|
|
|
Nothing. |
|
711
|
|
|
|
|
|
|
|
|
712
|
|
|
|
|
|
|
=head2 __parse_properties_file (Private) |
|
713
|
|
|
|
|
|
|
|
|
714
|
|
|
|
|
|
|
=head3 Parameters |
|
715
|
|
|
|
|
|
|
|
|
716
|
|
|
|
|
|
|
The path to a properties file on disk. The data in the file should be in the |
|
717
|
|
|
|
|
|
|
following format: |
|
718
|
|
|
|
|
|
|
|
|
719
|
|
|
|
|
|
|
key1=value1 |
|
720
|
|
|
|
|
|
|
key2=value2 |
|
721
|
|
|
|
|
|
|
|
|
722
|
|
|
|
|
|
|
=head3 Returns |
|
723
|
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
A hash corresponding to the keys and values in the properties file. |
|
725
|
|
|
|
|
|
|
|
|
726
|
|
|
|
|
|
|
=head3 Exceptions |
|
727
|
|
|
|
|
|
|
|
|
728
|
|
|
|
|
|
|
die()s with an error message if the properties file could not be read. |
|
729
|
|
|
|
|
|
|
|
|
730
|
|
|
|
|
|
|
=head2 _get_header (Protected) |
|
731
|
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
Used by the L class to get a valid request |
|
733
|
|
|
|
|
|
|
header corresponding to the current credentials in this |
|
734
|
|
|
|
|
|
|
Google::Ads::AdWords::Client instance. |
|
735
|
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=head3 Returns |
|
737
|
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
A hash reference with credentials corresponding to the values needed to be |
|
739
|
|
|
|
|
|
|
included in the request header. |
|
740
|
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
=head2 _auth_handler (Protected) |
|
742
|
|
|
|
|
|
|
|
|
743
|
|
|
|
|
|
|
Retrieves the active AuthHandler. All handlers are checked in the order |
|
744
|
|
|
|
|
|
|
OAuth2 Applications -> OAuth2 Service Accounts. |
|
745
|
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
=head3 Returns |
|
747
|
|
|
|
|
|
|
|
|
748
|
|
|
|
|
|
|
An implementation of L. |
|
749
|
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
751
|
|
|
|
|
|
|
|
|
752
|
|
|
|
|
|
|
Copyright 2011 Google Inc. |
|
753
|
|
|
|
|
|
|
|
|
754
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License"); |
|
755
|
|
|
|
|
|
|
you may not use this file except in compliance with the License. |
|
756
|
|
|
|
|
|
|
You may obtain a copy of the License at |
|
757
|
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0 |
|
759
|
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software |
|
761
|
|
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS, |
|
762
|
|
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
763
|
|
|
|
|
|
|
See the License for the specific language governing permissions and |
|
764
|
|
|
|
|
|
|
limitations under the License. |
|
765
|
|
|
|
|
|
|
|
|
766
|
|
|
|
|
|
|
=head1 REPOSITORY INFORMATION |
|
767
|
|
|
|
|
|
|
|
|
768
|
|
|
|
|
|
|
$Rev: $ |
|
769
|
|
|
|
|
|
|
$LastChangedBy: $ |
|
770
|
|
|
|
|
|
|
$Id: $ |
|
771
|
|
|
|
|
|
|
|
|
772
|
|
|
|
|
|
|
=cut |