• Stars
    star
    295
  • Rank 140,902 (Top 3 %)
  • Language
    PHP
  • License
    Apache License 2.0
  • Created over 6 years ago
  • Updated 28 days ago

Reviews

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

Repository Details

Google Ads API Client Library for PHP

Google Ads API Client Library for PHP

Minimum PHP Version Latest Stable Version Total Downloads License

Build Status codecov

This project hosts the PHP client library for the Google Ads API.

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.

Features

  • Distributed via Composer and Packagist.
  • Easy management of credentials.
  • Easy creation of Google Ads API service clients.

Requirements

  • Both 32-bit and 64-bit PHP systems are supported but we highly recommend to use 64-bit if you can. This is because many fields of the Google Ads API are typed as 64-bit integers and casting their values to 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.
  • 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.
  • System requirements and dependencies can be found in composer.json of this library.
    • PHP: You can find the required minimum PHP version in "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.
    • gRPC: To install the gRPC PHP extension, make sure to meet any additional requirements listed in the project's documentation. You can learn more about how gRPC is used by this library by reading our Transport guide. It usually take minutes to install using PECL:
      1. Install the extension using the command sudo pecl install grpc.
      2. Add a line extension=grpc.so to the php.ini file.
      3. Run php -i | grep grpc in a terminal: it is well installed and configured if it returns something
    • Protobuf: To install the Protobuf PHP extension, make sure to meet any additional requirements listed in the project's documentation. If you encounter any error during the installation, you can skip this step and the PHP implementation will be used instead. You can learn more about how Protobuf is used by this library by reading our Protobuf implementations guide. It usually take minutes to install using PECL:
      1. Install the extension using the command sudo pecl install protobuf.
      2. Add a line extension=protobuf.so to the php.ini file.
      3. Run php -i | grep protobuf in a terminal: it is well installed and configured if it returns something
  • You need a developer token to connect to the Google Ads API.
  • One version of the library typically supports multiple versions of the Google Ads API. You can check the CHANGELOG.md file to identify what versions of the library added or removed the support for a specific version of the Google Ads API. For example, the version V7 of the Google Ads API was added in the version v9.0.0 of the library as described here.

Getting started

Running code examples

Follow the below steps if you want to try our code examples.

  1. Clone this project in the directory of your choice via:

    git clone https://github.com/googleads/google-ads-php.git
    
  2. 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.
  3. Run composer install at the command prompt. This will install all dependencies needed for using the library and running examples.

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

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

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

Installing the library as your project's dependency

  1. Change into the root directory of your project.
  2. Run 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.
  3. Set up your OAuth2 credentials like described in the previous section.
  4. You can now use this library by importing its classes like shown in the code examples.

Basic usage

Instantiate a client

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.

Get a service client

Once you have an instance of GoogleAdsClient, you can obtain a service client for a particular service using one of the get...ServiceClient() methods.

The created service client can be either GAPIC (Generated API Client) v1 or v2 source code, based on the value of the useGapicV2Source configuration. See GAPIC and Configuration fields for details.

Client configuration

See the Configuration guide.

Transport

There are different types of transport that can be used. See the Transport guide for more information.

Protobuf

Protobuf is used regardless of the transport used to request the Google Ads API.

See the Protobuf guide for more information.

Running in a Docker container

See the Running in a Docker container guide.

Logging

See the Logging guide.

Proxy configuration

See the Proxy guide.

Performance

See the Performance guide.

Miscellaneous

Wiki

Issue tracker

API Documentation:

Support forum

Authors

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

googleads-php-lib

Google Ad Manager SOAP API Client Library for PHP
PHP
657
star
6

google-ads-python

Google Ads API Client Library for Python
Python
498
star
7

videojs-ima

IMA SDK Plugin for Video.js
JavaScript
449
star
8

googleads-mobile-flutter

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

google-api-ads-ruby

Ad Manager SOAP API Client Libraries for Ruby
Ruby
297
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