1
1
## Google Ads API PHP Client Library
2
2
3
- This project hosts the PHP client library for the various SOAP-based Ads APIs
4
- (AdWords and Ad Manager) at Google.
3
+ This repository hosts the PHP client library for the Google Ad Manager SOAP API.
5
4
6
- > ** The AdWords API is [ sunsetting ] ( https://ads-developers.googleblog.com/2022/04/reminder-requests-to-adwords-api-will.html ) .
5
+ > ** The AdWords API is [ sunset ] ( https://ads-developers.googleblog.com/2022/04/reminder-requests-to-adwords-api-will.html ) .
7
6
> You can use the new client library [ google-ads-php] ( https://github.com/googleads/google-ads-php ) to access the new [ Google Ads API] ( https://developers.google.com/google-ads/api/docs/start ) instead.**
8
7
9
8
[ ![ PHP version] ( https://badge.fury.io/ph/googleads%2Fgoogleads-php-lib.svg )] ( https://badge.fury.io/ph/googleads%2Fgoogleads-php-lib ) [ ![ Build Status] ( https://travis-ci.org/googleads/googleads-php-lib.svg?branch=main )] ( https://travis-ci.org/googleads/googleads-php-lib )
@@ -13,8 +12,8 @@ This project hosts the PHP client library for the various SOAP-based Ads APIs
13
12
* System requirements and dependencies can be found in ` composer.json ` of this
14
13
library. See [ this page] ( https://getcomposer.org/doc/01-basic-usage.md ) for
15
14
more details.
16
- * From version 52 .0.0, this library requires the minimum PHP version to be
17
- 7.3 . If you have an older version of PHP, ` composer ` command will
15
+ * From version 60 .0.0, this library requires the minimum PHP version to be
16
+ 7.4 . If you have an older version of PHP, ` composer ` command will
18
17
download an older version of the ` googleads/googleads-php-lib ` library.
19
18
* This library depends on [ Composer] ( https://getcomposer.org/ ) . If you don't
20
19
have it installed on your computer yet, follow the
@@ -23,24 +22,17 @@ This project hosts the PHP client library for the various SOAP-based Ads APIs
23
22
For the rest of this guide, we're assuming that you're using
24
23
Linux/Unix/OS X and have Composer installed [ globally] ( https://getcomposer.org/doc/00-intro.md#globally ) ,
25
24
thus, your installed Composer is available on the command line as ` composer ` .
26
- * To use this library to connect to AdWords API, you need an
27
- [ OAuth 2 client ID and secret] ( https://developers.google.com/adwords/api/docs/guides/first-api-call#oauth2_client_id_and_client_secret ) ,
28
- as well as a [ developer token] ( https://developers.google.com/adwords/api/docs/guides/first-api-call#developer_token ) .
29
- Make sure you've written down these credentials in advance.
30
25
31
26
### Getting started
32
27
33
- Copy the sample ` adsapi_php.ini ` for your product to your
28
+ Copy the sample [ Ad Manager
29
+ adsapi_php.ini] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager/adsapi_php.ini )
30
+ to your
34
31
[ home directory] ( https://en.wikipedia.org/wiki/Home_directory#Default_home_directory_per_operating_system )
35
32
and fill out the required properties before downloading the library.
36
33
This library determines the home directory of your computer by using
37
34
[ ` EnvironmentalVariables::getHome() ` ] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/Common/Util/EnvironmentalVariables.php#L34 ) .
38
35
39
- * [ AdWords
40
- adsapi_php.ini] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdWords/adsapi_php.ini )
41
- * [ Ad Manager
42
- adsapi_php.ini] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager/adsapi_php.ini )
43
-
44
36
### Downloading this library
45
37
46
38
There are three ways of downloading this library as described below.
@@ -95,65 +87,52 @@ this library (e.g., submitting pull requests) or wish to try our examples.
95
87
1. Follow [Setting up your OAuth2 credentials](#setting-up-your-oauth2-credentials)
96
88
if you haven't set up the credentials yet.
97
89
1. You can now use the library and run any examples you want. Try
98
- [GetCampaigns .php](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdWords/v201809/BasicOperations/GetCampaigns .php)
90
+ [GetAllNetworks .php](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager/v202211/NetworkService/GetAllNetworks .php)
99
91
by executing the following command:
100
92
101
93
```
102
- $ php examples/AdWords/v201806/BasicOperations/GetCampaigns .php
94
+ $ php examples/AdManager/v202211/NetworkService/GetAllNetworks .php
103
95
```
104
96
105
97
### Downloading a compressed tarball
106
98
107
- This is suitable for those who only want to try out the AdWords API with this
99
+ This is suitable for those who only want to try out the Ad Manager API with this
108
100
client library. The extracted directory of the tarball will contain only the
109
101
`examples/` directory.
110
102
111
103
1. On the [releases page](https://github.com/googleads/googleads-php-lib/releases),
112
104
select a version you want to try. Then, under **Download**, select the tarball
113
105
of your choice. The name of the tarball indicates which product it belongs to,
114
- for example, **adwords -examples-vX.Y.Z.tar.gz**.
106
+ for example, **admanager -examples-vX.Y.Z.tar.gz**.
115
107
1. Extract your downloaded file to any location on your computer.
116
- 1. Navigate to the extracted directory (for example, **adwords -examples-vX.Y.Z**).
108
+ 1. Navigate to the extracted directory (for example, **admanager -examples-vX.Y.Z**).
117
109
1. Run `composer install` at the command prompt. This will install all dependencies
118
110
needed for using the library and running examples.
119
111
1. Follow [Getting started](#getting-started) if you haven't done so.
120
112
1. Follow [Setting up your OAuth2 credentials](#setting-up-your-oauth2-credentials)
121
113
if you haven't set up the credentials yet.
122
114
1. You can now run any examples you want. Try
123
- [GetCampaigns .php](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdWords/v201809/BasicOperations/GetCampaigns .php)
115
+ [GetAllNetworks .php](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager/v202211/NetworkService/GetAllNetworks .php)
124
116
by executing the following command:
125
117
126
118
```
127
- $ php examples/AdWords/v201806/BasicOperations/GetCampaigns .php
119
+ $ php examples/AdManager/v202211/NetworkService/GetAllNetworks .php
128
120
```
129
121
130
122
### Setting up your OAuth2 credentials
131
123
132
- The AdWords and Ad Manager APIs use
133
- [OAuth2](https://oauth.net/2/) as the authentication mechanism. Follow the
134
- appropriate guide below based on your use case.
135
-
136
- **If you're accessing an API using your own credentials...**
137
-
138
- * [Using
139
- AdWords](https://github.com/googleads/googleads-php-lib/wiki/API-access-using-own-credentials-\(installed-application-flow\))
140
- * [Using
141
- Ad Manager](https://github.com/googleads/googleads-php-lib/wiki/API-access-using-own-credentials-\(server-to-server-flow\))
124
+ The Ad Manager API uses [OAuth2](https://oauth.net/2/) as the authentication
125
+ mechanism. Follow the appropriate guide below based on your use case:
142
126
143
- **If you're accessing an API on behalf of clients...**
144
-
145
- * [Using AdWords or
146
- Ad Manager ](https://github.com/googleads/googleads-php-lib/wiki/API-access-on-behalf-of-your-clients-\(web-flow\))
127
+ * [Using your own
128
+ credentials](https://github.com/googleads/googleads-php-lib/wiki/API-access-using-own-credentials-\(server-to-server-flow\))
129
+ * [Acting on behalf of
130
+ clients ](https://github.com/googleads/googleads-php-lib/wiki/API-access-on-behalf-of-your-clients-\(web-flow\))
147
131
148
132
### Basic usage
149
133
150
- The best way to learn how to use this library is to review the examples for your
151
- product.
152
-
153
- * [AdWords
154
- examples](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdWords)
155
- * [Ad Manager
156
- examples](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager)
134
+ The best way to learn how to use this library is to review the
135
+ [examples](https://github.com/googleads/googleads-php-lib/blob/HEAD/examples/AdManager).
157
136
158
137
> All our examples are meant to be run via the command line and not through a
159
138
> webpage.
@@ -164,44 +143,24 @@ product.
164
143
> when writing your own code, do _not_ apply `intval()` on any attributes that
165
144
> are explicitly an integer.
166
145
167
- The following snippet of code from the **BasicOperations/GetCampaigns.php**
168
- example for AdWords gives you an idea of how to use this library. The usage
169
- pattern is similar for Ad Manager.
146
+ The following snippet of code from the **GetAllNetworks.php** example gives you
147
+ an idea of how to use this library.
170
148
171
149
```php
172
- use Google\AdsApi\AdWords\AdWordsServices;
173
- use Google\AdsApi\AdWords\AdWordsSessionBuilder;
174
- use Google\AdsApi\AdWords\v201802\cm\CampaignService;
175
- use Google\AdsApi\AdWords\v201802\cm\OrderBy;
176
- use Google\AdsApi\AdWords\v201802\cm\Paging;
177
- use Google\AdsApi\AdWords\v201802\cm\Selector;
178
- use Google\AdsApi\Common\OAuth2TokenBuilder;
179
-
180
- $oAuth2Credential = (new OAuth2TokenBuilder())
181
- ->fromFile()
150
+ $oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()
182
151
->build();
183
152
184
- $session = (new AdWordsSessionBuilder())
185
- ->fromFile()
153
+ $session = (new AdManagerSessionBuilder())->fromFile()
186
154
->withOAuth2Credential($oAuth2Credential)
187
155
->build();
188
156
189
- $adWordsServices = new AdWordsServices();
190
-
191
- $campaignService = $adWordsServices->get($session, CampaignService::class);
157
+ $adManagerServices = new ServiceFactory();
192
158
193
- // Create selector.
194
- $selector = new Selector();
195
- $selector->setFields(array('Id', 'Name'));
196
- $selector->setOrdering(array(new OrderBy('Name', 'ASCENDING')));
159
+ $networkService = $adManagerServices->createNetworkService($session);
197
160
198
- // Create paging controls.
199
- $selector->setPaging(new Paging(0, 100));
161
+ $networks = $networkService->getAllNetworks();
200
162
201
- // Make the get request.
202
- $page = $campaignService->get($selector);
203
-
204
- // Do something with the $page.
163
+ // Do something with the $networks.
205
164
```
206
165
207
166
The builder's ` fromFile() ` method looks for an ` adsapi_php.ini ` file in your
@@ -217,40 +176,18 @@ don't want to or can't use one, you can use the OAuth2 token and ads session
217
176
builders instead to set the same information. See the builders for details:
218
177
219
178
* [ OAuth2TokenBuilder] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/Common/OAuth2TokenBuilder.php )
220
- * [ AdWordsSessionBuilder] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/AdWords/AdWordsSessionBuilder.php )
221
179
* [ AdManagerSessionBuilder] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/AdManager/AdManagerSessionBuilder.php )
222
180
223
181
### WSDL objects with names that are reserved PHP keywords
224
182
225
- #### Class names
226
-
227
- Note that some WSDL object types have names that are reserved PHP keywords and
228
- need to be augmented when used as PHP class names. The following is a list of
229
- these occurences.
230
-
231
- * [ Function] ( https://developers.google.com/adwords/api/docs/reference/latest/CampaignFeedService.Function )
232
- => ` MatchingFunction `
233
- * [ Parent] ( https://developers.google.com/adwords/api/docs/reference/latest/AdGroupCriterionService.Parent )
234
- => ` ParentCriterion `
235
-
236
- #### Constant names
237
-
238
183
Some WSDL enum values have names that are reserved PHP keywords and need to be
239
184
modified when used as PHP constant names. For example, ` AND ` and ` DEFAULT ` are
240
185
generated as ` AND_VALUE ` and ` DEFAULT_VALUE ` .
241
186
242
187
### Logging
243
188
244
189
This library conforms to [ PSR-3] ( http://www.php-fig.org/psr/psr-3 ) for logging
245
- and provides the following loggers:
246
-
247
- AdWords
248
-
249
- * SOAP logger
250
- * Report downloader logger
251
- * Batch jobs utility logger
252
-
253
- Ad Manager
190
+ and provides the following loggers for Ad Manager:
254
191
255
192
* SOAP logger
256
193
* Report downloader logger
@@ -285,10 +222,10 @@ soapLogLevel = "NOTICE"
285
222
If you need to further customize logging, you can specify your own logger
286
223
entirely by providing a logger that implements
287
224
[ LoggerInterface] ( https://github.com/php-fig/log/blob/master/Psr/Log/LoggerInterface.php )
288
- in either the AdWords or Ad Manager session builders :
225
+ in the Ad Manager session builder :
289
226
290
227
``` php
291
- $session = (new AdWordsSessionBuilder ())
228
+ $session = (new AdManagerSessionBuilder ())
292
229
...
293
230
->withSoapLogger(new MyCustomSoapLogger())
294
231
->withReportDownloaderLogger(new MyCustomReportDownloaderLogger())
@@ -297,13 +234,10 @@ $session = (new AdWordsSessionBuilder())
297
234
298
235
### Utilities
299
236
300
- We provide some utilities in this client library for helping you use features
301
- in the AdWords and Ad Manager API more conveniently. Check out the following wikis for
302
- details:
303
-
304
- * [ BatchJobs for AdWords] ( //github.com/googleads/googleads-php-lib/wiki/BatchJobs-for-AdWords )
305
- * [ ProductPartitions for AdWords] ( //github.com/googleads/googleads-php-lib/wiki/ProductPartitions-for-AdWords )
306
- * [ ReportDownloader Utilities] ( //github.com/googleads/googleads-php-lib/wiki/ReportDownloader-Utilities )
237
+ We provide some
238
+ [ utilities] ( //github.com/googleads/googleads-php-lib/wiki/ReportDownloader-Utilities )
239
+ in this client library for helping you use features in the Ad Manager API more
240
+ conveniently.
307
241
308
242
### Reporting
309
243
@@ -344,9 +278,9 @@ CA file issues can also cause an error like this:
344
278
```
345
279
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
346
280
Couldn't load from
347
- 'https://adwords .google.com/api/adwords/cm/v201806/CampaignService ?wsdl' :
281
+ 'https://ads .google.com/apis/ads/publisher/v202211/ActivityService ?wsdl' :
348
282
failed to load external entity
349
- "https://adwords .google.com/api/adwords/cm/v201806/CampaignService ?wsdl
283
+ "https://ads .google.com/apis/ads/publisher/v202211/ActivityService ?wsdl
350
284
```
351
285
352
286
To remedy, see [ Steps for troubleshooting CA file issues] ( https://github.com/googleads/googleads-php-lib/wiki/Steps-for-troubleshooting-CA-file-issues ) .
@@ -355,17 +289,11 @@ To remedy, see [Steps for troubleshooting CA file issues](https://github.com/goo
355
289
356
290
PHPDoc for this library can be found in the
357
291
[ gh-pages] ( https://github.com/googleads/googleads-php-lib/tree/gh-pages ) branch
358
- of this repository and can be viewed at:
359
-
360
- * [ AdWords] ( http://googleads.github.io/googleads-php-lib/AdWords/ )
361
- * [ Ad Manager] ( http://googleads.github.io/googleads-php-lib/AdManager/ )
292
+ of this repository. You can view the Ad Manager API site
293
+ [ here] ( http://googleads.github.io/googleads-php-lib/AdManager/ ) .
362
294
363
- General AdWords and Ad Manager API documentation can be found on our Google Developers
364
- site:
365
-
366
- * [ AdWords API documentation] ( https://developers.google.com/adwords/api )
367
- * [ Ad Manager API
368
- documentation] ( https://developers.google.com/ad-manager )
295
+ General Ad Manager API documentation can be found on our [ Google Developers
296
+ site] ( https://developers.google.com/ad-manager ) .
369
297
370
298
### Coding Style
371
299
@@ -389,22 +317,14 @@ For client library specific bug reports, feature requests, and patches,
389
317
create an issue on the [ issue
390
318
tracker] ( https://github.com/googleads/googleads-php-lib/issues ) .
391
319
392
- For general AdWords and Ad Manager API questions, bug reports, or feature requests,
393
- post to our forums:
394
-
395
- * [ AdWords API Forum] ( https://groups.google.com/forum/#!forum/adwords-api )
396
- * [ Ad Manager API
397
- Forum] ( https://groups.google.com/forum/#!forum/google-doubleclick-for-publishers-api )
320
+ For general Ad Manager API questions, bug reports, or feature requests, post to
321
+ the [ Ad Manager API
322
+ Forum] ( https://groups.google.com/forum/#!forum/google-doubleclick-for-publishers-api ) .
398
323
399
324
### Announcements and updates
400
325
401
- For general ads API and client library updates and news, follow:
402
-
403
- * [ Google Ads Developers blog] ( http://googleadsdeveloper.blogspot.com )
404
- * [ Ad Manager API Sunset Announcements mailing
405
- list] ( https://groups.google.com/forum/#!forum/dfpapi-sunset-announce )
406
-
407
- API deprecation schedules can be found at:
408
-
409
- * [ Ad Manager API deprecation
410
- schedule] ( https://developers.google.com/ad-manager/docs/deprecation )
326
+ For general Ad Manager API and client library updates and news, you can follow
327
+ the [ Sunset Announcements mailing
328
+ list] ( https://groups.google.com/forum/#!forum/dfpapi-sunset-announce )
329
+ and rely on the [ deprecation
330
+ schedule] ( https://developers.google.com/ad-manager/docs/deprecation ) .
0 commit comments