Git Product home page Git Product logo

googleads-php-lib's Introduction

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.

Welcome to the new ads API PHP client library!

The ads API PHP client library has been rewritten. If you're new to this library, read on! If you're already using our library, you may want to take a look at our Upgrading guide first.

Getting started

  1. Install the latest version using Composer.

    $ php composer.phar require googleads/googleads-php-lib
    
  2. Copy the sample adsapi_php.ini for your product to your home directory and fill out the required properties.

  3. 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...

    If you're accessing an API on behalf of clients...

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.

If you're using 32-bit PHP, you may need to change intval() of any examples to floatval() when running them. This is because some IDs would be larger than 32-bit PHP_INT_MAX. In that case, intval() would return incorrect values.

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.

use Google\AdsApi\AdWords\AdWordsServices;
use Google\AdsApi\AdWords\AdWordsSessionBuilder;
use Google\AdsApi\AdWords\v201609\cm\CampaignService;
use Google\AdsApi\AdWords\v201609\cm\OrderBy;
use Google\AdsApi\AdWords\v201609\cm\Paging;
use Google\AdsApi\AdWords\v201609\cm\Selector;
use Google\AdsApi\Common\OAuth2TokenBuilder;

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

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

$adWordsServices = new AdWordsServices();

$campaignService = $adWordsServices->get($session, CampaignService::class);

// Create selector.
$selector = new Selector();
$selector->setFields(array('Id', 'Name'));
$selector->setOrdering(array(new OrderBy('Name', 'ASCENDING')));

// Create paging controls.
$selector->setPaging(new Paging(0, 100));

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

// Do something with the $page.

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:

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 it, you can also use the OAuth2 token and ads session builders to set the same information. See the builders for details:

WSDL objects with names that are reserved PHP keywords

Class names

Note that some WSDL object types have names that are reserved PHP keywords and need to be augmented when used as PHP class names. The following is a list of these occurences.

Constant names

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

Logging

This library conforms to PSR-3 for logging and provides the following loggers:

AdWords

  • SOAP logger
  • Report downloader logger
  • Batch jobs utility logger

DFP

  • 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.

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.

You may configure some options for these default loggers in the adsapi_php.ini file. E.g.,

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

If you need to further customize logging, you may specify your own logger entirely by providing a logger that implements LoggerInterface in either the AdWords or DFP session builders:

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

Documentation

PHPDoc is not yet available for the new ads API PHP library. Please follow the PHPDoc issue for updates.

General AdWords and DFP API documentation can be found on our Google 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:

googleads-php-lib's People

Contributors

fiboknacky avatar vtsao avatar api-vtsao avatar saturnism avatar shakaran avatar gitazem avatar jrdnrc avatar c960657 avatar jclee100 avatar knobel-dk avatar steerfox avatar nosnickid avatar vikash avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.