• Stars
    star
    657
  • Rank 68,589 (Top 2 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created almost 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Google Ad Manager SOAP API Client Library for PHP

Google Ad Manager SOAP API Client Library for PHP

This repository hosts the PHP client library for the Google Ad Manager SOAP API.

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

PHP version Build Status

Requirements and Preparation

  • System requirements and dependencies can be found in composer.json of this library. See this page for more details.
  • From version 60.0.0, this library requires the minimum PHP version to be 7.4. 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().

Downloading this library

There are three ways of downloading this library as described below.

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.

  1. Install the latest version using Composer.

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

  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.

  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:

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

  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:

    $ 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:

Basic usage

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

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

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.

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

$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:

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:

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.

Logging

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

  • 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 can configure some options for these default loggers in the adsapi_php.ini file:

[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:

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

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.

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

SSL CA files

PHP >= v5.6 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().

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

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

CA file issues can also cause an error like this:

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.

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.

General Ad Manager API documentation can be found on our Google Developers site.

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

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

To automatically fix (fixable) coding style violations, run

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.

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

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.

More Repositories

1

googleads-mobile-android-examples

googleads-mobile-android
Java
1,693
star
2

googleads-mobile-unity

Official Unity Plugin for the Google Mobile Ads SDK
C#
1,355
star
3

googleads-mobile-ios-examples

googleads-mobile-ios
Objective-C
953
star
4

googleads-python-lib

The Python client library for Google's Ads APIs
Python
678
star
5

google-ads-python

Google Ads API Client Library for Python
Python
498
star
6

videojs-ima

IMA SDK Plugin for Video.js
JavaScript
449
star
7

googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Java
341
star
8

google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
Ruby
297
star
9

google-ads-php

Google Ads API Client Library for PHP
PHP
295
star
10

googleads-ima-html5

Samples for the HTML5 IMA SDK.
JavaScript
260
star
11

googleads-mobile-android-mediation

Sample Android project showcasing how to build a mediation adapter or custom event for the Google Mobile Ads SDK.
Java
240
star
12

googleads-java-lib

Google Ad Manager SOAP API Client Library for Java
Java
226
star
13

googleads-shopping-samples

Samples for the Content API for Shopping and the Manufacturer Center API
Java
192
star
14

google-ads-java

Google Ads API Client Library for Java
Java
167
star
15

google-media-framework-android

[DEPRECATED] The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on Android easier.
Java
155
star
16

googleads-adsense-examples

Samples for the AdSense Management API
Java
142
star
17

swift-package-manager-google-mobile-ads

Swift
133
star
18

googleads-mobile-ios-mediation

Objective-C
118
star
19

googleads-mobile-android-native-templates

Java
116
star
20

googleads-ima-android

Samples for the IMA Android SDK.
Java
114
star
21

googleads-dotnet-lib

Google Ad Manager SOAP API .NET client library
C#
108
star
22

googleads-dfa-reporting-samples

Samples for the DoubleClick for Advertisers Reporting and Trafficking API
C#
106
star
23

googleads-consent-sdk-android

Consent SDK
Java
101
star
24

publisher-ads-lighthouse-plugin

Publisher Ads Audits for Lighthouse is a tool to improve ad speed and overall quality through a series of automated audits. This tool will aid in resolving discovered problems, providing a tool to be used to evaluate effectiveness of iterative changes while suggesting actionable feedback.
JavaScript
98
star
25

google-media-framework-ios

The Google Media Framework (GMF) is a lightweight media player designed to make video playback and integration with the Google IMA SDK on iOS easier.
Objective-C
74
star
26

admob-ads-in-flutter

Dart
73
star
27

google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
C#
72
star
28

google-ads-ruby

Google Ads API Ruby Client Library
Ruby
70
star
29

googleads-ima-ios

Samples for the iOS IMA SDK.
Objective-C
57
star
30

googleads-bidmanager-examples

PHP
42
star
31

googleads-admob-api-samples

googleads-admob-api-samples
Java
40
star
32

admob-inline-ads-in-flutter

Dart
40
star
33

google-publisher-tag-samples

Google Publisher Tag (GPT) code samples.
TypeScript
36
star
34

googleads-adxbuyer-examples

Samples for the DoubleClick Ad Exchange Buyer REST API
C#
34
star
35

googleads-ima-html5-dai

JavaScript
33
star
36

google-ads-doctor

Go
31
star
37

googleads-consent-sdk-ios

Consent SDK
Objective-C
31
star
38

googleads-adxseller-examples

Samples for the DoubleClick Ad Exchange Seller REST API
Java
20
star
39

googleads-ima-roku-dai

Brightscript
15
star
40

google-ads-perl

Google Ads API Client Library for Perl
Perl
15
star
41

googleads-mobile-ios-native-templates

Objective-C
14
star
42

dfp-playground

JavaScript
14
star
43

googleads-ima-tvos-dai

Objective-C
11
star
44

adwords-scripts-linkchecker

App Engine-based link checker for AdWords Scripts and Apps Script
Java
11
star
45

googleads-ima-cast

Samples for the Chromecast IMA SDK
JavaScript
10
star
46

googleads-displayvideo-examples

Display & Video 360 (DV360) API code samples.
Java
10
star
47

angular-dfp

Semantic DoubleClick integration with AngularJS
JavaScript
10
star
48

authorized-buyers-rtb-api-samples

C#
9
star
49

googleads-dynamic-ad-insertion

JavaScript
9
star
50

googleads-dfp-java-dfp-playground

DFP API Playground
Java
9
star
51

googleads-viewability-insights-extension

A DevTools extension for inspecting the viewability of Ad Manager Ads.
JavaScript
9
star
52

app-conversion-solutions

App Conversion Solutions with Google Ads API
Java
8
star
53

google-publisher-tag-types

Automatically generated TypeScript type definitions for the Google Publisher Tag JavaScript API
TypeScript
8
star
54

mobilevsi-android

Java
7
star
55

googleads-ima-android-dai

Java
7
star
56

googleads-dfa-samples

Samples for the DoubleClick for Advertisers API
PHP
7
star
57

googleads-ima-cast-dai

JavaScript
6
star
58

admob-firebase-codelabs-android

Kotlin
6
star
59

googleads-ima-tvos-client-side

Objective-C
6
star
60

googleads-perl-lib

AdWords API Perl Client Library
Perl
5
star
61

googleads-ima-ios-dai

Objective-C
5
star
62

html5-to-dfp

Python
5
star
63

admob-firebase-codelabs-unity

C#
5
star
64

swift-package-manager-google-user-messaging-platform

Swift
5
star
65

googleads-pal-webapp

An app demonstrating PAL SDK
TypeScript
4
star
66

googleads-ima-tizen-dai

JavaScript
4
star
67

gpt-ad

A Polymer element for defining GPT Ads in Polymer apps.
HTML
4
star
68

swift-package-manager-google-programmatic-access-library-ios

Swift
4
star
69

admob-appopen-unity

C#
3
star
70

swift-package-manager-google-interactive-media-ads-tvos

Swift
3
star
71

gpt-light-ad

HTML
3
star
72

swift-package-manager-google-programmatic-access-library-tvos

Swift
2
star
73

authorized-buyers-marketplace-api-samples

C#
2
star
74

swift-package-manager-google-interactive-media-ads-ios

Swift
2
star
75

conf-data-processing-architecture-reference-sample

2
star
76

hbbtv-lshape-demo

JavaScript
2
star
77

googleads-pal

Java
2
star
78

search-campaign-setup-booster

Python
2
star
79

google-publisher-tag-playground

An interactive code playground for Google Publisher Tag (GPT) samples.
TypeScript
2
star
80

comparison-shopping-service-api-samples

Code samples for the Comparison Shopping Service API (CSS API)
Java
1
star
81

.allstar

1
star
82

.github

1
star