Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/latest'
Browse files Browse the repository at this point in the history
  • Loading branch information
masabni committed Jun 10, 2024
2 parents 577b579 + ea96cc2 commit 5fdf95b
Show file tree
Hide file tree
Showing 20,511 changed files with 913,279 additions and 1,213,132 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php

php:
- 7.3
- 7.4
- 8.0
- 8.1
- 8.2
- nightly

matrix:
Expand Down
75 changes: 75 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,78 @@
## 21.0.0
* Removed support for v12 of Google Ads API.
* Use [the GAPIC v2 source
code](https://developers.google.com/google-ads/api/docs/client-libs/php/gapic)
in `ResourceNames` and `ServiceClientFactoryTrait` of v14.
* Updated the source code to use PHP 8 features, e.g., named arguments,
private constants, constructor promotion, removing unused exception variables.
* Updated code examples:
* AddCampaigns
* GenerateKeywordIdeas
* Removed trivial code examples that can be easily obtained by changing small
parts of other code examples.

## 20.1.0
* Added support for v14_1 of Google Ads API.
* Removed the `final` modifier from `GoogleAdsClient`. This fixes
https://github.com/googleads/google-ads-php/issues/347.
* Fixed https://github.com/googleads/google-ads-php/issues/902 by passing
`linked-customer-id` to the header of a request.
* Made `GoogleAdsCallLogger::getNextFinerLogLevel` aligned with PSR-3
`LogLevel` enum by returning a lowercase string. This fixes
https://github.com/googleads/google-ads-php/issues/849.
* Fixed the issue of the check for grpc versions in
`GoogleAdsClientBuilder::validate()`. It now supports the case when
the system-package version is not found.
* Added support for [the GAPIC v2 source
code](https://developers.google.com/google-ads/api/docs/client-libs/php/gapic).
* Added support for the `useGapicV2Source` configuration.
* Updated all code examples to show how to use the GAPIC v2 source code.
* Added code examples:
* GenerateForecastMetrics (new version that uses `KeywordPlanIdeaService`)
* GenerateHistoricalMetrics (new version that uses `KeywordPlanIdeaService`)
* Removed AddKeywordPlan example.

## 20.0.0
* Updated `composer.json` to require the minimum PHP version of 8.0. See also
[README](README.md) for more details.
* Updated the minimum required version of `google/gax` to 1.19.1.
* Added a check for the versions of grpc installed by Composer and installed
as a platform package to `GoogleAdsClientBuilder::validate()`. This is a fix for
[#406](https://github.com/googleads/google-ads-php/issues/406).
* Fixed dependabot alert in `examples/LaravelSampleApp/composer.lock`.

## 19.2.0
* Added support for v14 of Google Ads API.
* Updated AddPerformanceMaxForTravelGoalsCampaign example.
* Removed code examples:
* GenerateForecastMetrics
* GenerateHistoricalMetrics
* GetCampaignCriterionBidModifierSimulations

## 19.1.0
* Added support for v13_1 of Google Ads API.
* Renamed the HotelAds example directory to Travel.
* Added AddThingsToDoAd example.
* Updated AddPerformanceMaxForTravelGoalsCampaign example.

## 19.0.0
* Removed support for v11 of Google Ads API.
* Updated CreateExperiment example.

## 18.0.0
* Added support for v13 of Google Ads API.
* Removed support for v10 of Google Ads API.
* Updated code examples:
* AddCustomerMatchUserList
* AddPerformanceMaxRetailCampaign
* GetAdGroupBidModifiers
* GetChangeDetails
* Reworked code examples to address the deprecation of combined rule user lists
and expression rule user lists:
* Edited SetUpAdvancedRemarketing and SetUpRemarketing
* Renamed AddCombinedRuleUserList to AddFlexibleRuleUserList
* Removed AddExpressionRuleUserList

## 17.1.0
* Added support for v12 of Google Ads API.
* Renamed HandleExpandedTextAdPolicyViolations to HandleResponsiveSearchAdPolicyViolations
Expand Down
43 changes: 27 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Google Ads API Client Library for PHP

[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%207.4-8892BF.svg)](https://www.php.net/supported-versions.php)
[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg)](https://www.php.net/supported-versions.php)
[![Latest Stable
Version](https://img.shields.io/packagist/v/googleads/google-ads-php.svg)](https://packagist.org/packages/googleads/google-ads-php)
[![Total Downloads](https://poser.pugx.org/googleads/google-ads-php/downloads.svg)](https://packagist.org/packages/googleads/google-ads-php)
Expand All @@ -13,6 +13,11 @@ Status](https://travis-ci.org/googleads/google-ads-php.svg?branch=master)](https
This project hosts the PHP client library for the [Google Ads
API](https://developers.google.com/google-ads/api/docs/start).

**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](https://github.com/googleads/google-ads-php/issues/880).
This means that the final version of the library that supports PHP 7 is [v19.2.0](https://github.com/googleads/google-ads-php/releases/tag/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](https://developers.google.com/google-ads/api/docs/sunset-dates#timetable). 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](https://getcomposer.org/) and
Expand Down Expand Up @@ -54,6 +59,10 @@ API](https://developers.google.com/google-ads/api/docs/start).

## 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
Expand Down Expand Up @@ -82,20 +91,6 @@ API](https://developers.google.com/google-ads/api/docs/start).
mechanism. Choose the appropriate option below based on your use case, and
read and follow the instructions that the example prints to the console.

**If you already have credentials for the AdWords API...**

* If you have the `adsapi_php.ini` file you used for the AdWords API,
copy and name it as `google_ads_php.ini`. Simply change the section name
from `[ADWORDS]` to `[GOOGLE_ADS]`.

* If you don't have the file, copy the sample `google_ads_php.ini` to your
[home
directory](https://en.wikipedia.org/wiki/Home_directory#Default_home_directory_per_operating_system).
This library determines the home directory of your computer by using
[`EnvironmentalVariables::getHome()`](https://github.com/googleads/google-ads-php/blob/HEAD/src/Google/Ads/GoogleAds/Util/EnvironmentalVariables.php#L36).

**If you're accessing the Google Ads API using your own credentials...**

* Copy the sample [`google_ads_php.ini`](examples/Authentication/google_ads_php.ini)
to your [home
directory](https://en.wikipedia.org/wiki/Home_directory#Default_home_directory_per_operating_system).
Expand Down Expand Up @@ -134,12 +129,22 @@ API](https://developers.google.com/google-ads/api/docs/start).
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.
1. 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.
1. **Set up your OAuth2 credentials** like described in the previous section.
1. You can now use this library by importing its classes like shown in the [code
examples](examples/).

## Basic usage

### Instantiate a client

To issue requests via the Google Ads API, you first need to create a
[GoogleAdsClient](https://github.com/googleads/google-ads-php/blob/HEAD/src/Google/Ads/GoogleAds/Lib/V12/GoogleAdsClient.php).
[GoogleAdsClient](https://github.com/googleads/google-ads-php/blob/HEAD/src/Google/Ads/GoogleAds/Lib/V14/GoogleAdsClient.php).

For more information on how to configure a client when instantiating it, see the
[configuration guide](https://developers.google.com/google-ads/api/docs/client-libs/php/configuration).
Expand All @@ -149,6 +154,12 @@ For more information on how to configure a client when instantiating it, see the
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](https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/gapic)
and [Configuration fields](https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/configuration#config-field)
for details.

## Client configuration

See the [Configuration guide](https://developers.google.com/google-ads/api/docs/client-libs/php/configuration).
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Google Ads API client for PHP",
"require": {
"php": ">=7.3",
"google/gax": "^1.13.0",
"google/gax": "^1.18.1",
"grpc/grpc": "^1.36.0",
"google/protobuf": "^3.21.5",
"monolog/monolog": "^1.26 || ^2.0 || ^3.0"
Expand Down
31 changes: 20 additions & 11 deletions examples/AccountManagement/ApproveMerchantCenterLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsException;
use Google\Ads\GoogleAds\Util\FieldMasks;
use Google\Ads\GoogleAds\V12\Enums\MerchantCenterLinkStatusEnum\MerchantCenterLinkStatus;
use Google\Ads\GoogleAds\V12\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V12\Resources\MerchantCenterLink;
use Google\Ads\GoogleAds\V12\Services\MerchantCenterLinkOperation;
use Google\Ads\GoogleAds\V12\Services\MerchantCenterLinkServiceClient;
use Google\Ads\GoogleAds\V14\Enums\MerchantCenterLinkStatusEnum\MerchantCenterLinkStatus;
use Google\Ads\GoogleAds\V14\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V14\Resources\MerchantCenterLink;
use Google\Ads\GoogleAds\V14\Services\Client\MerchantCenterLinkServiceClient;
use Google\Ads\GoogleAds\V14\Services\ListMerchantCenterLinksRequest;
use Google\Ads\GoogleAds\V14\Services\MerchantCenterLinkOperation;
use Google\Ads\GoogleAds\V14\Services\MutateMerchantCenterLinkRequest;
use Google\ApiCore\ApiException;

/**
Expand Down Expand Up @@ -67,6 +69,12 @@ public static function main()
// OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
->withOAuth2Credential($oAuth2Credential)
// We set this value to true to show how to use GAPIC v2 source code. You can remove the
// below line if you wish to use the old-style source code. Note that in that case, you
// probably need to modify some parts of the code below to make it work.
// For more information, see
// https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/gapic.
->usingGapicV2Source(true)
->build();

try {
Expand Down Expand Up @@ -117,7 +125,9 @@ public static function runExample(
// [START approve_merchant_center_link]
// Lists all merchant links of the specified customer ID.
$merchantCenterLinkServiceClient = $googleAdsClient->getMerchantCenterLinkServiceClient();
$response = $merchantCenterLinkServiceClient->listMerchantCenterLinks($customerId);
$response = $merchantCenterLinkServiceClient->listMerchantCenterLinks(
ListMerchantCenterLinksRequest::build($customerId)
);
printf(
"%d Merchant Center link(s) found with the following details:%s",
$response->getMerchantCenterLinks()->count(),
Expand Down Expand Up @@ -189,8 +199,7 @@ private static function updateMerchantCenterLinkStatus(
// Issues a mutate request to update the Merchant Center link and prints some
// information.
$response = $merchantCenterLinkServiceClient->mutateMerchantCenterLink(
$customerId,
$merchantCenterLinkOperation
MutateMerchantCenterLinkRequest::build($customerId, $merchantCenterLinkOperation)
);
printf(
"Approved a Merchant Center Link with resource name '%s' to the Google Ads "
Expand Down
24 changes: 16 additions & 8 deletions examples/AccountManagement/CreateCustomer.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
use GetOpt\GetOpt;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\V12\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V12\Resources\Customer;
use Google\Ads\GoogleAds\V14\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V14\Resources\Customer;
use Google\Ads\GoogleAds\V14\Services\CreateCustomerClientRequest;
use Google\ApiCore\ApiException;

/**
Expand All @@ -54,9 +55,14 @@ public static function main()

// Construct a Google Ads client configured from a properties file and the
// OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())
->fromFile()
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
->withOAuth2Credential($oAuth2Credential)
// We set this value to true to show how to use GAPIC v2 source code. You can remove the
// below line if you wish to use the old-style source code. Note that in that case, you
// probably need to modify some parts of the code below to make it work.
// For more information, see
// https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/gapic.
->usingGapicV2Source(true)
->build();

try {
Expand Down Expand Up @@ -114,7 +120,9 @@ public static function runExample(GoogleAdsClient $googleAdsClient, int $manager

// Issues a mutate request to create an account
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
$response = $customerServiceClient->createCustomerClient($managerCustomerId, $customer);
$response = $customerServiceClient->createCustomerClient(
CreateCustomerClientRequest::build($managerCustomerId, $customer)
);

printf(
'Created a customer with resource name "%s" under the manager account with '
Expand Down
39 changes: 27 additions & 12 deletions examples/AccountManagement/GetAccountHierarchy.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@
use Google\Ads\GoogleAds\Examples\Utils\ArgumentNames;
use Google\Ads\GoogleAds\Examples\Utils\ArgumentParser;
use Google\Ads\GoogleAds\Lib\OAuth2TokenBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\V12\GoogleAdsServerStreamDecorator;
use Google\Ads\GoogleAds\V12\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V12\Resources\CustomerClient;
use Google\Ads\GoogleAds\V12\Services\CustomerServiceClient;
use Google\Ads\GoogleAds\V12\Services\GoogleAdsRow;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClient;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsClientBuilder;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsException;
use Google\Ads\GoogleAds\Lib\V14\GoogleAdsServerStreamDecorator;
use Google\Ads\GoogleAds\V14\Errors\GoogleAdsError;
use Google\Ads\GoogleAds\V14\Resources\CustomerClient;
use Google\Ads\GoogleAds\V14\Services\CustomerServiceClient;
use Google\Ads\GoogleAds\V14\Services\GoogleAdsRow;
use Google\Ads\GoogleAds\V14\Services\ListAccessibleCustomersRequest;
use Google\Ads\GoogleAds\V14\Services\SearchGoogleAdsStreamRequest;
use Google\ApiCore\ApiException;

/**
Expand All @@ -55,7 +57,7 @@ class GetAccountHierarchy

// Stores the mapping from the root customer IDs (the ones that will be used as a start point
// for printing each hierarchy) to their `CustomerClient` objects.
private static $rootCustomerClients = [];
private static array $rootCustomerClients = [];

public static function main()
{
Expand Down Expand Up @@ -83,6 +85,12 @@ public static function main()
// OAuth2 credentials above.
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
->withOAuth2Credential($oAuth2Credential)
// We set this value to true to show how to use GAPIC v2 source code. You can remove the
// below line if you wish to use the old-style source code. Note that in that case, you
// probably need to modify some parts of the code below to make it work.
// For more information, see
// https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/gapic.
->usingGapicV2Source(true)
->build();

try {
Expand Down Expand Up @@ -202,6 +210,12 @@ private static function createCustomerClientToHierarchy(
$googleAdsClient = (new GoogleAdsClientBuilder())->fromFile()
->withOAuth2Credential($oAuth2Credential)
->withLoginCustomerId($loginCustomerId ?? $rootCustomerId)
// We set this value to true to show how to use GAPIC v2 source code. You can remove the
// below line if you wish to use the old-style source code. Note that in that case, you
// probably need to modify some parts of the code below to make it work.
// For more information, see
// https://developers.devsite.corp.google.com/google-ads/api/docs/client-libs/php/gapic.
->usingGapicV2Source(true)
->build();

// Creates the Google Ads Service client.
Expand All @@ -225,10 +239,10 @@ private static function createCustomerClientToHierarchy(
$customerIdToSearch = array_shift($managerCustomerIdsToSearch);
// Issues a search request by specifying page size.
/** @var GoogleAdsServerStreamDecorator $stream */
$stream = $googleAdsServiceClient->searchStream(
$stream = $googleAdsServiceClient->searchStream(SearchGoogleAdsStreamRequest::build(
$customerIdToSearch,
$query
);
));

// Iterates over all elements to get all customer clients under the specified customer's
// hierarchy.
Expand Down Expand Up @@ -285,7 +299,8 @@ private static function getAccessibleCustomers(GoogleAdsClient $googleAdsClient)
// Issues a request for listing all customers accessible by this authenticated Google
// account.
$customerServiceClient = $googleAdsClient->getCustomerServiceClient();
$accessibleCustomers = $customerServiceClient->listAccessibleCustomers();
$accessibleCustomers =
$customerServiceClient->listAccessibleCustomers(new ListAccessibleCustomersRequest());

print 'No manager customer ID is specified. The example will print the hierarchies of'
. ' all accessible customer IDs:' . PHP_EOL;
Expand Down
Loading

0 comments on commit 5fdf95b

Please sign in to comment.