This project hosts the PHP client library for the Google Ads API. It adheres to the PHP sunset schedule and updates the composer.json file four to five months after the minimum required PHP version reaches its end-of-life. Based on the existing supported PHP versions, the update occurs about once a year.
IMPORTANT The Google Ads API client library for PHP has been updated to require PHP version 8 as the minimum version, as announced in #880. This means that the final version of the library that supports PHP 7 is v19.2.0, which supports Google Ads API v12 to v14.
Google Ads API v14 is scheduled to be sunset by the end of May 2024. Therefore, PHP 7 users have about 11 months to migrate to PHP 8 in order to continue using the library without disruption.
int
instead of float
from 32-bit systems can lead to issues. The largest integer value supported in 32-bit PHP systems is usually 2147483647, see the predefined constant PHP_INT_MAX for more details.composer
."php"
under the require
key of composer.json
. We usually set it to the minimum PHP version for which the PHP development team still provide security fixes. Whenever such a version is sunset, we'll update the composer file accordingly. Currently, the update frequency is around once a year based on the official schedule.
Visit this page for introduction to PHP.PECL
:
sudo pecl install grpc
.extension=grpc.so
to the php.ini
file.php -i | grep grpc
in a terminal: it is well installed
and configured if it returns somethingPECL
:
sudo pecl install protobuf
.extension=protobuf.so
to the php.ini
file.php -i | grep protobuf
in a terminal: it is well installed
and configured if it returns somethingV7
of the Google Ads API was added in the version v9.0.0
of the library as described here.Follow the below steps if you want to try our code examples.
Clone this project in the directory of your choice via:
git clone https://github.com/googleads/google-ads-php.git
Change into the google-ads-php
directory.
cd google-ads-php
You'll see some files and subdirectories:
composer.json
: the composer file, which holds the requirements of this
library.src
: source code of the library.tests
: tests of the library code.examples
: many examples that demonstrate how to use the library to
execute common use cases via the Google Ads API.metadata
: some metadata files used internally by the source code.
They're automatically generated files, so you shouldn't modify them.Run composer install
at the command prompt. This will install all
dependencies needed for using the library and running examples.
Set up your OAuth2 credentials.
The Google Ads API uses OAuth2 as the authentication mechanism. Choose the appropriate option below based on your use case, and read and follow the instructions that the example prints to the console.
Copy the sample google_ads_php.ini
to your home
directory.
This library determines the home directory of your computer by using
EnvironmentalVariables::getHome()
.
Follow the instructions at https://developers.google.com/google-ads/api/docs/oauth/cloud-project to create an OAuth2 client ID and secret for the installed application OAuth2 flow.
Run the GenerateUserCredentials example, which will prompt you for your OAuth2 client ID and secret.
Copy the output from the last step of the example into the
google_ads_php.ini
file in your home directory. Don't forget to fill
in your developer token too.
Run the GetCampaigns example to test if your credentials are valid. You also need to pass your Google Ads account's customer ID without dashes as a command-line parameter:
php examples/BasicOperations/GetCampaigns.php --customerId <YOUR_CUSTOMER_ID>
NOTE: Code examples are meant to be run from command prompt, not via the web browsers.
Explore other examples.
The examples directory contains several useful examples. Most of
the examples require parameters. You can see what are required by running
code examples with --help
as a command-line parameter.
Note: You will find comments with the formats [START...]
and [END...]
in the source code of these examples. These are only used for technical purposes,
you can completely disregard them.
composer require googleads/google-ads-php
at the command prompt. This
will install this library and all its dependencies in the vendor/
directory of your project's root directory.To issue requests via the Google Ads API, you first need to create a GoogleAdsClient.
For more information on how to configure a client when instantiating it, see the configuration guide.
Once you have an instance of GoogleAdsClient
, you can obtain a service client
for a particular service using one of the get...ServiceClient()
methods.
See the Configuration guide.
There are different types of transport that can be used. See the Transport guide for more information.
Protobuf is used regardless of the transport used to request the Google Ads API.
See the Protobuf guide for more information.
See the Running in a Docker container guide.
See the Logging guide.
See the Proxy guide.
See the Performance guide.