11## Google Ads API PHP Client Library
22
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.
54
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 ) .
76> 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.**
87
98[ ![ 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
1312* System requirements and dependencies can be found in ` composer.json ` of this
1413 library. See [ this page] ( https://getcomposer.org/doc/01-basic-usage.md ) for
1514 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
1817 download an older version of the ` googleads/googleads-php-lib ` library.
1918* This library depends on [ Composer] ( https://getcomposer.org/ ) . If you don't
2019 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
2322 For the rest of this guide, we're assuming that you're using
2423 Linux/Unix/OS X and have Composer installed [ globally] ( https://getcomposer.org/doc/00-intro.md#globally ) ,
2524 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.
3025
3126### Getting started
3227
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
3431[ home directory] ( https://en.wikipedia.org/wiki/Home_directory#Default_home_directory_per_operating_system )
3532and fill out the required properties before downloading the library.
3633This library determines the home directory of your computer by using
3734[ ` EnvironmentalVariables::getHome() ` ] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/Common/Util/EnvironmentalVariables.php#L34 ) .
3835
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-
4436### Downloading this library
4537
4638There 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.
95871. Follow [Setting up your OAuth2 credentials](#setting-up-your-oauth2-credentials)
9688 if you haven't set up the credentials yet.
97891. 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)
9991 by executing the following command:
10092
10193 ```
102- $ php examples/AdWords/v201806/BasicOperations/GetCampaigns .php
94+ $ php examples/AdManager/v202211/NetworkService/GetAllNetworks .php
10395 ```
10496
10597### Downloading a compressed tarball
10698
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
108100client library. The extracted directory of the tarball will contain only the
109101`examples/` directory.
110102
1111031. On the [releases page](https://github.com/googleads/googleads-php-lib/releases),
112104 select a version you want to try. Then, under **Download**, select the tarball
113105 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**.
1151071. 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**).
1171091. Run `composer install` at the command prompt. This will install all dependencies
118110 needed for using the library and running examples.
1191111. Follow [Getting started](#getting-started) if you haven't done so.
1201121. Follow [Setting up your OAuth2 credentials](#setting-up-your-oauth2-credentials)
121113 if you haven't set up the credentials yet.
1221141. 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)
124116 by executing the following command:
125117
126118 ```
127- $ php examples/AdWords/v201806/BasicOperations/GetCampaigns .php
119+ $ php examples/AdManager/v202211/NetworkService/GetAllNetworks .php
128120 ```
129121
130122### Setting up your OAuth2 credentials
131123
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:
142126
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\))
147131
148132### Basic usage
149133
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).
157136
158137> All our examples are meant to be run via the command line and not through a
159138> webpage.
@@ -164,44 +143,24 @@ product.
164143> when writing your own code, do _not_ apply `intval()` on any attributes that
165144> are explicitly an integer.
166145
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.
170148
171149```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()
182151 ->build();
183152
184- $session = (new AdWordsSessionBuilder())
185- ->fromFile()
153+ $session = (new AdManagerSessionBuilder())->fromFile()
186154 ->withOAuth2Credential($oAuth2Credential)
187155 ->build();
188156
189- $adWordsServices = new AdWordsServices();
190-
191- $campaignService = $adWordsServices->get($session, CampaignService::class);
157+ $adManagerServices = new ServiceFactory();
192158
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);
197160
198- // Create paging controls.
199- $selector->setPaging(new Paging(0, 100));
161+ $networks = $networkService->getAllNetworks();
200162
201- // Make the get request.
202- $page = $campaignService->get($selector);
203-
204- // Do something with the $page.
163+ // Do something with the $networks.
205164```
206165
207166The 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
217176builders instead to set the same information. See the builders for details:
218177
219178* [ 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 )
221179* [ AdManagerSessionBuilder] ( https://github.com/googleads/googleads-php-lib/blob/HEAD/src/Google/AdsApi/AdManager/AdManagerSessionBuilder.php )
222180
223181### WSDL objects with names that are reserved PHP keywords
224182
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-
238183Some WSDL enum values have names that are reserved PHP keywords and need to be
239184modified when used as PHP constant names. For example, ` AND ` and ` DEFAULT ` are
240185generated as ` AND_VALUE ` and ` DEFAULT_VALUE ` .
241186
242187### Logging
243188
244189This 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:
254191
255192* SOAP logger
256193* Report downloader logger
@@ -285,10 +222,10 @@ soapLogLevel = "NOTICE"
285222If you need to further customize logging, you can specify your own logger
286223entirely by providing a logger that implements
287224[ 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 :
289226
290227``` php
291- $session = (new AdWordsSessionBuilder ())
228+ $session = (new AdManagerSessionBuilder ())
292229 ...
293230 ->withSoapLogger(new MyCustomSoapLogger())
294231 ->withReportDownloaderLogger(new MyCustomReportDownloaderLogger())
@@ -297,13 +234,10 @@ $session = (new AdWordsSessionBuilder())
297234
298235### Utilities
299236
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.
307241
308242### Reporting
309243
@@ -344,9 +278,9 @@ CA file issues can also cause an error like this:
344278```
345279Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
346280Couldn'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' :
348282failed 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
350284```
351285
352286To 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
355289
356290PHPDoc for this library can be found in the
357291[ 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/ ) .
362294
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 ) .
369297
370298### Coding Style
371299
@@ -389,22 +317,14 @@ For client library specific bug reports, feature requests, and patches,
389317create an issue on the [ issue
390318tracker] ( https://github.com/googleads/googleads-php-lib/issues ) .
391319
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 ) .
398323
399324### Announcements and updates
400325
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