2017 © Pedro Peláez
 

library googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

image

googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  • Thursday, July 19, 2018
  • by vtsao
  • Repository
  • 98 Watchers
  • 385 Stars
  • 1,660,761 Installations
  • PHP
  • 15 Dependents
  • 1 Suggesters
  • 499 Forks
  • 6 Open issues
  • 69 Versions
  • 15 % Grown

The README.md

This repository hosts the PHP client library for the Google Ad Manager SOAP API., (*1)

The AdWords API is sunset. You can use the new client library google-ads-php to access the new Google Ads API instead., (*2)

Minimum PHP Version Latest Stable
Version Total Downloads License, (*3)

IMPORTANT This client library has been updated to require PHP version 8.0 as the minimum version, as announced in #777. This means that the final version of the library that supports PHP 7 is v61.0.0, which supports Google Ad Manager API v202208, v202211, v202302, and v202305., (*4)

Google Ad Manager API v202305 is scheduled to be sunset in May 2024. Therefore, PHP 7 users have about a year to migrate to the version 8.0 or higher of PHP to avoid disruption., (*5)

Requirements and Preparation

  • System requirements and dependencies can be found in composer.json of this library. See this page for more details.
  • From version 62.0.0, this library requires the minimum PHP version to be 8.0. If you have an older version of PHP, composer command will download an older version of the googleads/googleads-php-lib library.
  • This library depends on Composer. If you don't have it installed on your computer yet, follow the installation guide for Linux/Unix/OS X or installation guide for Windows. For the rest of this guide, we're assuming that you're using Linux/Unix/OS X and have Composer installed globally, thus, your installed Composer is available on the command line as composer.

Getting started

Copy the sample Ad Manager adsapi_php.ini to your home directory and fill out the required properties before downloading the library. This library determines the home directory of your computer by using EnvironmentalVariables::getHome()., (*6)

Downloading this library

There are three ways of downloading this library as described below., (*7)

Method Target Users
Using composer require Those who want to use this library as a third-party library for their projects and thus example files are not needed.
Using git clone Those who want to alter or contribute to this library (e.g., submitting a pull request) or want to run example files.
Downloading a compressed tarball Those who only want to run example files.

Note

  • If you don't have OAuth2 credentials prior to using installed application flow, you'll need examples/Auth/GetRefreshToken.php. In this case, using composer require is not an option since there are no example files downloaded with the library.
  • Our examples are meant to be run from the command line and not as a webpage. If you run them as a webpage, results may not be shown properly.

Using composer require

The steps below download this library as a third-party library for your projects. The library will be downloaded by Composer and stored under the vendor/ directory. Examples are NOT downloaded by this download method., (*8)

  1. Install the latest version using Composer., (*9)

    $ composer require googleads/googleads-php-lib
    
  2. Follow Getting started if you haven't done so., (*10)

  3. Follow Setting up your OAuth2 credentials if you haven't set up the credentials yet.
  4. You can now use the library.

Using git clone

This method is suitable for those who want to alter or contribute to this library (e.g., submitting pull requests) or wish to try our examples. All files in this repository will be downloaded., (*11)

  1. Run git clone https://github.com/googleads/googleads-php-lib.git at the command prompt.
  2. You'll get a googleads-php-lib directory. Navigate to it by running cd googleads-php-lib.
  3. Run composer install at the command prompt. This will install all dependencies needed for using the library and running examples.
  4. Follow Getting started if you haven't done so.
  5. Follow Setting up your OAuth2 credentials if you haven't set up the credentials yet.
  6. You can now use the library and run any examples you want. Try GetAllNetworks.php by executing the following command:, (*12)

    $ php examples/AdManager/v202211/NetworkService/GetAllNetworks.php
    

Downloading a compressed tarball

This is suitable for those who only want to try out the Ad Manager API with this client library. The extracted directory of the tarball will contain only the examples/ directory., (*13)

  1. On the releases page, select a version you want to try. Then, under Download, select the tarball of your choice. The name of the tarball indicates which product it belongs to, for example, admanager-examples-vX.Y.Z.tar.gz.
  2. Extract your downloaded file to any location on your computer.
  3. Navigate to the extracted directory (for example, admanager-examples-vX.Y.Z).
  4. Run composer install at the command prompt. This will install all dependencies needed for using the library and running examples.
  5. Follow Getting started if you haven't done so.
  6. Follow Setting up your OAuth2 credentials if you haven't set up the credentials yet.
  7. You can now run any examples you want. Try GetAllNetworks.php by executing the following command:, (*14)

    $ php examples/AdManager/v202211/NetworkService/GetAllNetworks.php
    

Setting up your OAuth2 credentials

The Ad Manager API uses OAuth2 as the authentication mechanism. Follow the appropriate guide below based on your use case:, (*15)

Basic usage

The best way to learn how to use this library is to review the examples., (*16)

All our examples are meant to be run via the command line and not through a webpage., (*17)

If you're using 32-bit PHP, you'll need to change all instances of intval() to floatval() before running an example. This is due to some IDs exceeding the 32-bit PHP_INT_MAX that intval() changes your value to. In addition, when writing your own code, do not apply intval() on any attributes that are explicitly an integer., (*18)

The following snippet of code from the GetAllNetworks.php example gives you an idea of how to use this library., (*19)

$oAuth2Credential = (new OAuth2TokenBuilder())->fromFile()
    ->build();

$session = (new AdManagerSessionBuilder())->fromFile()
    ->withOAuth2Credential($oAuth2Credential)
    ->build();

$adManagerServices = new ServiceFactory();

$networkService = $adManagerServices->createNetworkService($session);

$networks = $networkService->getAllNetworks();

// Do something with the $networks.

The builder's fromFile() method looks for an adsapi_php.ini file in your home directory by default. If you want to store this file in another directory, pass the path of the file as an argument. For example:, (*20)

fromFile('/config/myprops.ini')

It is highly recommended that you use an adsapi_php.ini file. However, if you don't want to or can't use one, you can use the OAuth2 token and ads session builders instead to set the same information. See the builders for details:, (*21)

WSDL objects with names that are reserved PHP keywords

Some WSDL enum values have names that are reserved PHP keywords and need to be modified when used as PHP constant names. For example, AND and DEFAULT are generated as AND_VALUE and DEFAULT_VALUE., (*22)

Logging

This library conforms to PSR-3 for logging and provides the following loggers for Ad Manager:, (*23)

  • SOAP logger
  • Report downloader logger

In general, each logger logs a summary and debug message for events (e.g., a SOAP API call). The level at which messages are logged depends on whether the event succeeded., (*24)

Log message \ Event status Success Failure
One-line summary INFO WARNING
Debug message (e.g., SOAP payload) DEBUG NOTICE

Configuring logging

By default, each of the library loggers logs to STDERR on a separate channel using a Monolog StreamHandler., (*25)

You can configure some options for these default loggers in the adsapi_php.ini file:, (*26)

[LOGGING]
; Optional logging settings.
soapLogFilePath = "path/to/your/soap.log"
soapLogLevel = "NOTICE"

If you need to further customize logging, you can specify your own logger entirely by providing a logger that implements LoggerInterface in the Ad Manager session builder:, (*27)

$session = (new AdManagerSessionBuilder())
    ...
    ->withSoapLogger(new MyCustomSoapLogger())
    ->withReportDownloaderLogger(new MyCustomReportDownloaderLogger())
    ->build();

Utilities

We provide some utilities in this client library for helping you use features in the Ad Manager API more conveniently., (*28)

Reporting

When downloading reports, you can set additional stream context options using the stream_context key to suit your needs (e.g., increasing the timeout as shown below). See also Guzzle FAQ for details., (*29)

$options = [
    'stream_context' => [
        'http' => ['timeout' => 120]
    ]
];
$requestOptionsFactory = new RequestOptionsFactory($session, $options);
$reportDownloader = new ReportDownloader($session, $requestOptionsFactory);

SSL CA files

PHP automatically sets verify_peer to true and will do its best to find the most appropriate CA bundle on your system by default. However, not all systems have a known CA bundle on disk (e.g. Windows). This library tries to locate CA bundles on your system by using Guzzle default_ca_bundle()., (*30)

If this library can't find a CA bundle on your system, you'll get an error message similar to this:, (*31)

cURL error 60: SSL certificate problem: unable to get local issuer certificate.

CA file issues can also cause an error like this:, (*32)

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL:
Couldn't load from
'https://ads.google.com/apis/ads/publisher/v202211/ActivityService?wsdl' :
failed to load external entity
"https://ads.google.com/apis/ads/publisher/v202211/ActivityService?wsdl

To remedy, see Steps for troubleshooting CA file issues., (*33)

Documentation

PHPDoc for this library can be found in the gh-pages branch of this repository. You can view the Ad Manager API site here., (*34)

General Ad Manager API documentation can be found on our Google Developers site., (*35)

Coding Style

We use PSR-2 as a coding style standard. Assuming that you're at the root directory of your project, to check for coding style violations, run, (*36)

vendor/bin/phpcs src --standard=phpcs_ruleset.xml -np

To automatically fix (fixable) coding style violations, run, (*37)

vendor/bin/phpcbf src --standard=phpcs_ruleset.xml

Getting support

For client library specific bug reports, feature requests, and patches, create an issue on the issue tracker., (*38)

For general Ad Manager API questions, bug reports, or feature requests, post to the Ad Manager API Forum., (*39)

Announcements and updates

For general Ad Manager API and client library updates and news, you can follow the Sunset Announcements mailing list and rely on the deprecation schedule., (*40)

The Versions

05/12 2017
15/11 2017

32.0.0

32.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

12/10 2017

31.0.0

31.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

20/09 2017

30.0.0

30.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

16/08 2017

29.0.0

29.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

10/08 2017

28.1.0

28.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

 

The Development Requires

30/06 2017
26/06 2017

dev-deprecated

dev-deprecated https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

26/06 2017

19.0.0

19.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

01/06 2017
01/06 2017

18.1.0

18.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

24/05 2017

18.0.0

18.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

24/05 2017
28/04 2017
17/03 2017

17.0.0

17.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

03/03 2017
01/03 2017

16.1.0

16.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

01/03 2017
14/02 2017
14/02 2017

16.0.0

16.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

11/01 2017
22/12 2016
07/12 2016

15.0.0

15.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

25/10 2016

14.0.0

14.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

04/10 2016

13.1.0

13.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

02/09 2016

13.0.0

13.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

26/08 2016

12.0.0

12.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

23/08 2016

11.0.0

11.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0
  • ext-curl *
  • ext-openssl *
  • ext-soap *

 

29/07 2016

10.1.0

10.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

20/06 2016

10.0.0

10.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

30/05 2016

9.1.0

9.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

17/05 2016

9.0.0

9.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

08/04 2016

8.3.0

8.3.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

05/04 2016

8.2.1

8.2.1.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

24/03 2016

8.2.0

8.2.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

23/02 2016

8.1.0

8.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

03/02 2016

8.0.0

8.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

24/12 2015

7.0.0

7.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

19/11 2015

6.6.0

6.6.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

09/11 2015

6.5.0

6.5.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

14/10 2015

6.4.0

6.4.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

26/08 2015

6.3.0

6.3.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

28/07 2015

6.2.0

6.2.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

01/07 2015

6.1.0

6.1.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.3.0

 

by Vincent Tsao

19/05 2015

6.0.0

6.0.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

01/05 2015

5.9.0

5.9.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

18/03 2015

5.8.2

5.8.2.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

26/02 2015

5.8.1

5.8.1.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

24/02 2015

5.8.0

5.8.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

11/12 2014

5.7.1

5.7.1.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

09/12 2014

5.7.0

5.7.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

12/11 2014

5.6.0

5.6.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

10/10 2014

5.5.2

5.5.2.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

22/08 2014

5.5.1

5.5.1.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

21/08 2014

5.5.0

5.5.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

22/07 2014

5.4.0

5.4.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

09/07 2014

5.3.1

5.3.1.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

13/06 2014

5.3.0

5.3.0.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

11/04 2014

5.2.3

5.2.3.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang

01/04 2014

5.2.2

5.2.2.0 https://github.com/googleads/googleads-php-lib

Google Ads APIs Client Library for PHP (AdWords, Adx, and DFP)

  Sources   Download

Apache-2.0

The Requires

  • php >=5.2.0

 

by Paul Matthews
by Mat Scales
by Vincent Tsao
by Ray Tsang