Google Ads Ad Manager V1 Client - Class CreativeServiceClient (0.17.0)

Reference documentation and code samples for the Google Ads Ad Manager V1 Client class CreativeServiceClient.

Service Description: Provides methods for handling Creative objects.

This class provides the ability to make remote calls to the backing service through method calls that map to API methods.

Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parseName method to extract the individual identifiers contained within formatted names that are returned by the API.

Namespace

Google \ Ads \ AdManager \ V1 \ Client

Methods

__construct

Constructor.

Parameters
Name Description
options array|Google\ApiCore\Options\ClientOptions

Optional. Options for configuring the service API wrapper.

↳ apiEndpoint string

The address of the API remote host. May optionally include the port, formatted as "

↳ credentials Google\Auth\FetchAuthTokenInterface|Google\ApiCore\CredentialsWrapper

This option should only be used with a pre-constructed Google\Auth\FetchAuthTokenInterface or Google\ApiCore\CredentialsWrapper object. Note that when one of these objects are provided, any settings in $credentialsConfig will be ignored. Important: If you are providing a path to a credentials file, or a decoded credentials file as a PHP array, this usage is now DEPRECATED. Providing an unvalidated credential configuration to Google APIs can compromise the security of your systems and data. It is recommended to create the credentials explicitly use Google\Auth\Credentials\ServiceAccountCredentials; use Google\Ads\AdManager\V1\CreativeServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new CreativeServiceClient(['credentials' => $creds]); https://cloud.google.com/docs/authentication/external/externally-sourced-credentials

↳ credentialsConfig array

Options used to configure credentials, including auth token caching, for the client. For a full list of supporting configuration options, see Google\ApiCore\CredentialsWrapper::build() .

↳ disableRetries bool

Determines whether or not retries defined by the client configuration should be disabled. Defaults to false.

↳ clientConfig string|array

Client method configuration, including retry settings. This option can be either a path to a JSON file, or a PHP array containing the decoded JSON data. By default this settings points to the default client config file, which is provided in the resources folder.

↳ transport string|Google\ApiCore\Transport\TransportInterface

The transport used for executing network requests. At the moment, supports only rest. Advanced usage: Additionally, it is possible to pass in an already instantiated Google\ApiCore\Transport\TransportInterface object. Note that when this object is provided, any settings in $transportConfig, and any $apiEndpoint setting, will be ignored.

↳ transportConfig array

Configuration options that will be used to construct the transport. Options for each supported transport type should be passed in a key for that transport. For example: $transportConfig = [ 'rest' => [...], ]; See the Google\ApiCore\Transport\RestTransport::build() method for the supported options.

↳ clientCertSource callable

A callable which returns the client cert as a string. This can be used to provide a certificate and private key to the transport layer for mTLS.

↳ logger false|Psr\Log\LoggerInterface

A PSR-3 compliant logger. If set to false, logging is disabled, ignoring the 'GOOGLE_SDK_PHP_LOGGING' environment flag

↳ universeDomain string

The service domain for the client. Defaults to 'googleapis.com'.

batchActivateCreatives

Batch activates Creative objects.

The async variant is CreativeServiceClient::batchActivateCreativesAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchActivateCreativesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchActivateCreativesResponse
Example
use Google\Ads\AdManager\V1\BatchActivateCreativesRequest;
use Google\Ads\AdManager\V1\BatchActivateCreativesResponse;
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent       Format: `networks/{network_code}`
 *                                      Please see {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $formattedNamesElement The resource names of the `Creative`s to activate.
 *                                      Format: `networks/{network_code}/creatives/{creative_id}`
 *                                      Please see {@see CreativeServiceClient::creativeName()} for help formatting this field.
 */
function batch_activate_creatives_sample(
    string $formattedParent,
    string $formattedNamesElement
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $formattedNames = [$formattedNamesElement];
    $request = (new BatchActivateCreativesRequest())
        ->setParent($formattedParent)
        ->setNames($formattedNames);

    // Call the API and handle any network failures.
    try {
        /** @var BatchActivateCreativesResponse $response */
        $response = $creativeServiceClient->batchActivateCreatives($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $formattedNamesElement = CreativeServiceClient::creativeName('[NETWORK_CODE]', '[CREATIVE]');

    batch_activate_creatives_sample($formattedParent, $formattedNamesElement);
}

batchCreateCreatives

Creates Creative objects.

The async variant is CreativeServiceClient::batchCreateCreativesAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchCreateCreativesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchCreateCreativesResponse
Example
use Google\Ads\AdManager\V1\BatchCreateCreativesRequest;
use Google\Ads\AdManager\V1\BatchCreateCreativesResponse;
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\CreateCreativeRequest;
use Google\Ads\AdManager\V1\Creative;
use Google\Ads\AdManager\V1\Size;
use Google\Ads\AdManager\V1\SizeTypeEnum\SizeType;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent                     The parent resource where `Creatives` will be created.
 *                                                    Format: `networks/{network_code}`
 *                                                    The parent field in the CreateCreativeRequest must match this
 *                                                    field. Please see
 *                                                    {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $formattedRequestsParent             The parent resource where this `Creative` will be created.
 *                                                    Format: `networks/{network_code}`
 *                                                    Please see {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $requestsCreativeDisplayName         Display name of the `Creative`. This attribute has a maximum
 *                                                    length of 255 characters.
 * @param string $formattedRequestsCreativeAdvertiser The resource name of the Company, which is of type
 *                                                    Company.Type.ADVERTISER, to which this Creative belongs. Format:
 *                                                    "networks/{network_code}/companies/{company_id}"
 *                                                    Please see {@see CreativeServiceClient::companyName()} for help formatting this field.
 * @param int    $requestsCreativeSizeWidth           The width of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $requestsCreativeSizeHeight          The height of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $requestsCreativeSizeSizeType        The SizeType of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 */
function batch_create_creatives_sample(
    string $formattedParent,
    string $formattedRequestsParent,
    string $requestsCreativeDisplayName,
    string $formattedRequestsCreativeAdvertiser,
    int $requestsCreativeSizeWidth,
    int $requestsCreativeSizeHeight,
    int $requestsCreativeSizeSizeType
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $requestsCreativeSize = (new Size())
        ->setWidth($requestsCreativeSizeWidth)
        ->setHeight($requestsCreativeSizeHeight)
        ->setSizeType($requestsCreativeSizeSizeType);
    $requestsCreative = (new Creative())
        ->setDisplayName($requestsCreativeDisplayName)
        ->setAdvertiser($formattedRequestsCreativeAdvertiser)
        ->setSize($requestsCreativeSize);
    $createCreativeRequest = (new CreateCreativeRequest())
        ->setParent($formattedRequestsParent)
        ->setCreative($requestsCreative);
    $requests = [$createCreativeRequest];
    $request = (new BatchCreateCreativesRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchCreateCreativesResponse $response */
        $response = $creativeServiceClient->batchCreateCreatives($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $formattedRequestsParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $requestsCreativeDisplayName = '[DISPLAY_NAME]';
    $formattedRequestsCreativeAdvertiser = CreativeServiceClient::companyName(
        '[NETWORK_CODE]',
        '[COMPANY]'
    );
    $requestsCreativeSizeWidth = 0;
    $requestsCreativeSizeHeight = 0;
    $requestsCreativeSizeSizeType = SizeType::SIZE_TYPE_UNSPECIFIED;

    batch_create_creatives_sample(
        $formattedParent,
        $formattedRequestsParent,
        $requestsCreativeDisplayName,
        $formattedRequestsCreativeAdvertiser,
        $requestsCreativeSizeWidth,
        $requestsCreativeSizeHeight,
        $requestsCreativeSizeSizeType
    );
}

batchDeactivateCreatives

Deactivates a list of Creative objects.

The async variant is CreativeServiceClient::batchDeactivateCreativesAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchDeactivateCreativesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchDeactivateCreativesResponse
Example
use Google\Ads\AdManager\V1\BatchDeactivateCreativesRequest;
use Google\Ads\AdManager\V1\BatchDeactivateCreativesResponse;
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent       Format: `networks/{network_code}`
 *                                      Please see {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $formattedNamesElement The resource names of the `Creative`s to deactivate.
 *                                      Format: `networks/{network_code}/creatives/{creative_id}`
 *                                      Please see {@see CreativeServiceClient::creativeName()} for help formatting this field.
 */
function batch_deactivate_creatives_sample(
    string $formattedParent,
    string $formattedNamesElement
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $formattedNames = [$formattedNamesElement];
    $request = (new BatchDeactivateCreativesRequest())
        ->setParent($formattedParent)
        ->setNames($formattedNames);

    // Call the API and handle any network failures.
    try {
        /** @var BatchDeactivateCreativesResponse $response */
        $response = $creativeServiceClient->batchDeactivateCreatives($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $formattedNamesElement = CreativeServiceClient::creativeName('[NETWORK_CODE]', '[CREATIVE]');

    batch_deactivate_creatives_sample($formattedParent, $formattedNamesElement);
}

batchUpdateCreatives

Batch updates Creative objects.

The async variant is CreativeServiceClient::batchUpdateCreativesAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchUpdateCreativesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\BatchUpdateCreativesResponse
Example
use Google\Ads\AdManager\V1\BatchUpdateCreativesRequest;
use Google\Ads\AdManager\V1\BatchUpdateCreativesResponse;
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\Creative;
use Google\Ads\AdManager\V1\Size;
use Google\Ads\AdManager\V1\SizeTypeEnum\SizeType;
use Google\Ads\AdManager\V1\UpdateCreativeRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent                     The parent resource where `Creatives` will be updated.
 *                                                    Format: `networks/{network_code}`
 *                                                    The parent field in the UpdateCreativeRequest must match this
 *                                                    field. Please see
 *                                                    {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $requestsCreativeDisplayName         Display name of the `Creative`. This attribute has a maximum
 *                                                    length of 255 characters.
 * @param string $formattedRequestsCreativeAdvertiser The resource name of the Company, which is of type
 *                                                    Company.Type.ADVERTISER, to which this Creative belongs. Format:
 *                                                    "networks/{network_code}/companies/{company_id}"
 *                                                    Please see {@see CreativeServiceClient::companyName()} for help formatting this field.
 * @param int    $requestsCreativeSizeWidth           The width of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $requestsCreativeSizeHeight          The height of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $requestsCreativeSizeSizeType        The SizeType of the Creative,
 *                                                    [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 */
function batch_update_creatives_sample(
    string $formattedParent,
    string $requestsCreativeDisplayName,
    string $formattedRequestsCreativeAdvertiser,
    int $requestsCreativeSizeWidth,
    int $requestsCreativeSizeHeight,
    int $requestsCreativeSizeSizeType
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $requestsCreativeSize = (new Size())
        ->setWidth($requestsCreativeSizeWidth)
        ->setHeight($requestsCreativeSizeHeight)
        ->setSizeType($requestsCreativeSizeSizeType);
    $requestsCreative = (new Creative())
        ->setDisplayName($requestsCreativeDisplayName)
        ->setAdvertiser($formattedRequestsCreativeAdvertiser)
        ->setSize($requestsCreativeSize);
    $updateCreativeRequest = (new UpdateCreativeRequest())
        ->setCreative($requestsCreative);
    $requests = [$updateCreativeRequest];
    $request = (new BatchUpdateCreativesRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchUpdateCreativesResponse $response */
        $response = $creativeServiceClient->batchUpdateCreatives($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $requestsCreativeDisplayName = '[DISPLAY_NAME]';
    $formattedRequestsCreativeAdvertiser = CreativeServiceClient::companyName(
        '[NETWORK_CODE]',
        '[COMPANY]'
    );
    $requestsCreativeSizeWidth = 0;
    $requestsCreativeSizeHeight = 0;
    $requestsCreativeSizeSizeType = SizeType::SIZE_TYPE_UNSPECIFIED;

    batch_update_creatives_sample(
        $formattedParent,
        $requestsCreativeDisplayName,
        $formattedRequestsCreativeAdvertiser,
        $requestsCreativeSizeWidth,
        $requestsCreativeSizeHeight,
        $requestsCreativeSizeSizeType
    );
}

createCreative

Creates a Creative object.

The async variant is CreativeServiceClient::createCreativeAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\CreateCreativeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Creative
Example
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\CreateCreativeRequest;
use Google\Ads\AdManager\V1\Creative;
use Google\Ads\AdManager\V1\Size;
use Google\Ads\AdManager\V1\SizeTypeEnum\SizeType;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent             The parent resource where this `Creative` will be created.
 *                                            Format: `networks/{network_code}`
 *                                            Please see {@see CreativeServiceClient::networkName()} for help formatting this field.
 * @param string $creativeDisplayName         Display name of the `Creative`. This attribute has a maximum
 *                                            length of 255 characters.
 * @param string $formattedCreativeAdvertiser The resource name of the Company, which is of type
 *                                            Company.Type.ADVERTISER, to which this Creative belongs. Format:
 *                                            "networks/{network_code}/companies/{company_id}"
 *                                            Please see {@see CreativeServiceClient::companyName()} for help formatting this field.
 * @param int    $creativeSizeWidth           The width of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $creativeSizeHeight          The height of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $creativeSizeSizeType        The SizeType of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 */
function create_creative_sample(
    string $formattedParent,
    string $creativeDisplayName,
    string $formattedCreativeAdvertiser,
    int $creativeSizeWidth,
    int $creativeSizeHeight,
    int $creativeSizeSizeType
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $creativeSize = (new Size())
        ->setWidth($creativeSizeWidth)
        ->setHeight($creativeSizeHeight)
        ->setSizeType($creativeSizeSizeType);
    $creative = (new Creative())
        ->setDisplayName($creativeDisplayName)
        ->setAdvertiser($formattedCreativeAdvertiser)
        ->setSize($creativeSize);
    $request = (new CreateCreativeRequest())
        ->setParent($formattedParent)
        ->setCreative($creative);

    // Call the API and handle any network failures.
    try {
        /** @var Creative $response */
        $response = $creativeServiceClient->createCreative($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');
    $creativeDisplayName = '[DISPLAY_NAME]';
    $formattedCreativeAdvertiser = CreativeServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');
    $creativeSizeWidth = 0;
    $creativeSizeHeight = 0;
    $creativeSizeSizeType = SizeType::SIZE_TYPE_UNSPECIFIED;

    create_creative_sample(
        $formattedParent,
        $creativeDisplayName,
        $formattedCreativeAdvertiser,
        $creativeSizeWidth,
        $creativeSizeHeight,
        $creativeSizeSizeType
    );
}

getCreative

Retrieves a Creative object.

The async variant is CreativeServiceClient::getCreativeAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\GetCreativeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Creative
Example
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\Creative;
use Google\Ads\AdManager\V1\GetCreativeRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The resource name of the Creative.
 *                              Format: `networks/{network_code}/creatives/{creative_id}`
 *                              Please see {@see CreativeServiceClient::creativeName()} for help formatting this field.
 */
function get_creative_sample(string $formattedName): void
{
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $request = (new GetCreativeRequest())
        ->setName($formattedName);

    // Call the API and handle any network failures.
    try {
        /** @var Creative $response */
        $response = $creativeServiceClient->getCreative($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedName = CreativeServiceClient::creativeName('[NETWORK_CODE]', '[CREATIVE]');

    get_creative_sample($formattedName);
}

listCreatives

Lists Creative objects.

The async variant is CreativeServiceClient::listCreativesAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\ListCreativesRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\ApiCore\PagedListResponse
Example
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\ListCreativesRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

/**
 * @param string $formattedParent The parent, which owns this collection of Creatives.
 *                                Format: networks/{network_code}
 *                                Please see {@see CreativeServiceClient::networkName()} for help formatting this field.
 */
function list_creatives_sample(string $formattedParent): void
{
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $request = (new ListCreativesRequest())
        ->setParent($formattedParent);

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $creativeServiceClient->listCreatives($request);

        foreach ($response as $element) {
            printf('Element data: %s' . PHP_EOL, $element->serializeToJsonString());
        }
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $formattedParent = CreativeServiceClient::networkName('[NETWORK_CODE]');

    list_creatives_sample($formattedParent);
}

updateCreative

Updates a Creative object.

The async variant is CreativeServiceClient::updateCreativeAsync() .

Parameters
Name Description
request Google\Ads\AdManager\V1\UpdateCreativeRequest

A request to house fields associated with the call.

callOptions array

Optional.

↳ retrySettings Google\ApiCore\RetrySettings|array

Retry settings to use for this call. Can be a Google\ApiCore\RetrySettings object, or an associative array of retry settings parameters. See the documentation on Google\ApiCore\RetrySettings for example usage.

Returns
Type Description
Google\Ads\AdManager\V1\Creative
Example
use Google\Ads\AdManager\V1\Client\CreativeServiceClient;
use Google\Ads\AdManager\V1\Creative;
use Google\Ads\AdManager\V1\Size;
use Google\Ads\AdManager\V1\SizeTypeEnum\SizeType;
use Google\Ads\AdManager\V1\UpdateCreativeRequest;
use Google\ApiCore\ApiException;

/**
 * @param string $creativeDisplayName         Display name of the `Creative`. This attribute has a maximum
 *                                            length of 255 characters.
 * @param string $formattedCreativeAdvertiser The resource name of the Company, which is of type
 *                                            Company.Type.ADVERTISER, to which this Creative belongs. Format:
 *                                            "networks/{network_code}/companies/{company_id}"
 *                                            Please see {@see CreativeServiceClient::companyName()} for help formatting this field.
 * @param int    $creativeSizeWidth           The width of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $creativeSizeHeight          The height of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 * @param int    $creativeSizeSizeType        The SizeType of the Creative,
 *                                            [AdUnit][google.ads.admanager.v1.AdUnit], or LineItem.
 */
function update_creative_sample(
    string $creativeDisplayName,
    string $formattedCreativeAdvertiser,
    int $creativeSizeWidth,
    int $creativeSizeHeight,
    int $creativeSizeSizeType
): void {
    // Create a client.
    $creativeServiceClient = new CreativeServiceClient();

    // Prepare the request message.
    $creativeSize = (new Size())
        ->setWidth($creativeSizeWidth)
        ->setHeight($creativeSizeHeight)
        ->setSizeType($creativeSizeSizeType);
    $creative = (new Creative())
        ->setDisplayName($creativeDisplayName)
        ->setAdvertiser($formattedCreativeAdvertiser)
        ->setSize($creativeSize);
    $request = (new UpdateCreativeRequest())
        ->setCreative($creative);

    // Call the API and handle any network failures.
    try {
        /** @var Creative $response */
        $response = $creativeServiceClient->updateCreative($request);
        printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString());
    } catch (ApiException $ex) {
        printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage());
    }
}

/**
 * Helper to execute the sample.
 *
 * This sample has been automatically generated and should be regarded as a code
 * template only. It will require modifications to work:
 *  - It may require correct/in-range values for request initialization.
 *  - It may require specifying regional endpoints when creating the service client,
 *    please see the apiEndpoint client configuration option for more details.
 */
function callSample(): void
{
    $creativeDisplayName = '[DISPLAY_NAME]';
    $formattedCreativeAdvertiser = CreativeServiceClient::companyName('[NETWORK_CODE]', '[COMPANY]');
    $creativeSizeWidth = 0;
    $creativeSizeHeight = 0;
    $creativeSizeSizeType = SizeType::SIZE_TYPE_UNSPECIFIED;

    update_creative_sample(
        $creativeDisplayName,
        $formattedCreativeAdvertiser,
        $creativeSizeWidth,
        $creativeSizeHeight,
        $creativeSizeSizeType
    );
}

batchActivateCreativesAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchActivateCreativesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchActivateCreativesResponse>

batchCreateCreativesAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchCreateCreativesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchCreateCreativesResponse>

batchDeactivateCreativesAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchDeactivateCreativesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchDeactivateCreativesResponse>

batchUpdateCreativesAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\BatchUpdateCreativesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\BatchUpdateCreativesResponse>

createCreativeAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\CreateCreativeRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Creative>

getCreativeAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\GetCreativeRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Creative>

listCreativesAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\ListCreativesRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\ApiCore\PagedListResponse>

updateCreativeAsync

Parameters
Name Description
request Google\Ads\AdManager\V1\UpdateCreativeRequest
optionalArgs array
Returns
Type Description
GuzzleHttp\Promise\PromiseInterface<Google\Ads\AdManager\V1\Creative>

static::assetName

Formats a string containing the fully-qualified path to represent a asset resource.

Parameters
Name Description
networkCode string
asset string
Returns
Type Description
string The formatted asset resource.

static::companyName

Formats a string containing the fully-qualified path to represent a company resource.

Parameters
Name Description
networkCode string
company string
Returns
Type Description
string The formatted company resource.

static::creativeName

Formats a string containing the fully-qualified path to represent a creative resource.

Parameters
Name Description
networkCode string
creative string
Returns
Type Description
string The formatted creative resource.

static::creativeSetName

Formats a string containing the fully-qualified path to represent a creative_set resource.

Parameters
Name Description
networkCode string
creativeSet string
Returns
Type Description
string The formatted creative_set resource.

static::customFieldName

Formats a string containing the fully-qualified path to represent a custom_field resource.

Parameters
Name Description
networkCode string
customField string
Returns
Type Description
string The formatted custom_field resource.

static::labelName

Formats a string containing the fully-qualified path to represent a label resource.

Parameters
Name Description
networkCode string
label string
Returns
Type Description
string The formatted label resource.

static::networkName

Formats a string containing the fully-qualified path to represent a network resource.

Parameter
Name Description
networkCode string
Returns
Type Description
string The formatted network resource.

static::thirdPartyCompanyName

Formats a string containing the fully-qualified path to represent a third_party_company resource.

Parameters
Name Description
networkCode string
thirdPartyCompany string
Returns
Type Description
string The formatted third_party_company resource.

static::parseName

Parses a formatted name string and returns an associative array of the components in the name.

The following name formats are supported: Template: Pattern

  • asset: networks/{network_code}/assets/{asset}
  • company: networks/{network_code}/companies/{company}
  • creative: networks/{network_code}/creatives/{creative}
  • creativeSet: networks/{network_code}/creativeSets/{creative_set}
  • customField: networks/{network_code}/customFields/{custom_field}
  • label: networks/{network_code}/labels/{label}
  • network: networks/{network_code}
  • thirdPartyCompany: networks/{network_code}/thirdPartyCompanies/{third_party_company}

The optional $template argument can be supplied to specify a particular pattern, and must match one of the templates listed above. If no $template argument is provided, or if the $template argument does not match one of the templates listed, then parseName will check each of the supported templates, and return the first match.

Parameters
Name Description
formattedName string

The formatted name string

template ?string

Optional name of template to match

Returns
Type Description
array An associative array from name component IDs to component values.