Skip to content

david-navarro/googleads-php-lib

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google Ads API PHP Client Library

This project hosts the PHP client library for the various SOAP-based Ads APIs (AdWords and DFP) at Google.

Requirements

PHP

Testing

Getting started

  1. Download and install the client library.

Download the latest examples and lib tarball distribution from the releases section. To install the client library, either copy the contents of the lib/ folder into a location on your PHP include path, or add the current directory path of the lib/ folder to your PHP include path.

  1. [Alternative] install via Composer.

You may also install this library via Composer.

$ php composer.phar require googleads/googleads-php-lib

Caveats with using Composer

Because this library isn't namespaced (see issue #4), there are some class naming conflicts with versioned utilities. E.g., [src/Google/Api/Ads/AdWords/Util] (https://github.com/googleads/googleads-php-lib/tree/master/src/Google/Api/Ads/AdWords/Util). Thus, these versioned utility src paths aren't included in the classmap of composer.json. So if you use composer, you will need to manually specify the version of the utility files you're using. E.g., if you're using AdWords v201603, then in your project's composer.json file, you can add those utility files to your classmap:

"classmap": [
  "vendor/googleads/googleads-php-lib/src/Google/Api/Ads/AdWords/Util/v201603"
]
  1. Copy the sample auth.ini and settings.ini for your product to your home directory and fill out the required properties.
  1. Setup your OAuth2 credentials.

The AdWords and DoubleClick for Publishers APIs use OAuth2 as the authentication mechanism. Follow the appropriate guide below based on your use case.

If you're accessing an API using your own credentials...

Basic usage

The best way to learn how to use this library is to review the examples for your product.

All our examples are meant to be run via the command line and not as a webpage.

The following snippet of code from the BasicOperations/GetCampaigns.php example for AdWords gives you an idea of how to use this library. The usage pattern is similar for DFP.

require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';

$user = new AdWordsUser();

$campaignService = $user->GetService('CampaignService', 'v201603');

// Create selector.
$selector = new Selector();
$selector->fields = array('Id', 'Name');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');

// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

// Make the get request.
$page = $campaignService->get($selector);

// Do something with the $page.

The AdWordsUser constructor method looks for an auth.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:

$user = new AdWordsUser('/config/myprops.ini');

It is highly recommended that you use an auth.ini file. However, if you don't want to or can't use it, you can also set the same information using the AdWordsUser or DfpUser constructor. See the example for your product for details.

How do I set different client customer IDs than specified in auth.ini?

You can do this by calling SetClientCustomerId() on an AdWordsUser:

// Create an AdWordsUser instance using the default constructor, which will load
// information from the auth.ini file as described above.
$user = new AdWordsUser();
$user->SetClientCustomerId('INSERT_CLIENT_CUSTOMER_ID_HERE');

Configuring logging

The client library uses a custom class for all logging purposes that is exposed through the Logger.php file. There are two loggers within this class described below.

  • REQUEST_INFO_LOG: Logs all requests from the client library along with information such as the timestamp, email, service, method, request ID, response time and which server was used. The default behavior is to log this information to "request_info.log" relative to your project's home directory.

  • SOAP_XML_LOG: Logs all incoming and outgoing SOAP requests/responses. The default behavior is to log this information to "soap_xml.log" relative to your project's home directory. Sensitive information, such as authentication tokens, will be stripped.

Logging can be enabled using the following methods.

  • $user->LogDefaults(): Logs request information for all requests, but only logs SOAP XML for requests that resulted in an error.

  • $user->LogErrors(): Only logs request information and SOAP XML for requests that resulted in an error.

  • $user->LogAll(): Logs request information and SOAP XML for all requests.

You can use the methods of the Logger class directly for even more control over how requests are logged.

Documentation

PHPDoc for this library can be found in the gh-pages branch of this repository and can be viewed at:

General AdWords and DFP API documentation can be found on our Developers site.

Getting support

For client library specific bug reports, feature requests, and patches, please create an issue on the issue tracker.

For general AdWords and DFP API questions, bug reports, or feature requests, please post to our API forums:

Announcements and updates

For general ads API and client library updates and news, please follow or join our:

API deprecation schedules can be found at:

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%