Google Ads Ad Manager V1 Client - Class SiteServiceClient (0.5.0)

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

Service Description: Provides methods for handling Site 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
FetchAuthTokenInterface|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\SiteServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new SiteServiceClient(['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|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|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'.

batchCreateSites

API to batch create Site objects.

The async variant is SiteServiceClient::batchCreateSitesAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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.

Example
 use Google\Ads\AdManager\V1\BatchCreateSitesRequest;
use Google\Ads\AdManager\V1\BatchCreateSitesResponse;
use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\CreateSiteRequest;
use Google\Ads\AdManager\V1\Site;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent         The parent resource where `Sites` will be created.
 *                                        Format: `networks/{network_code}`
 *                                        The parent field in the CreateSiteRequest must match this
 *                                        field. Please see
 *                                        {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $formattedRequestsParent The parent resource where this `Site` will be created.
 *                                        Format: `networks/{network_code}`
 *                                        Please see {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $requestsSiteUrl         The URL of the Site.
 */
function batch_create_sites_sample(
    string $formattedParent,
    string $formattedRequestsParent,
    string $requestsSiteUrl
): void {
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $requestsSite = (new Site())
        ->setUrl($requestsSiteUrl);
    $createSiteRequest = (new CreateSiteRequest())
        ->setParent($formattedRequestsParent)
        ->setSite($requestsSite);
    $requests = [$createSiteRequest,];
    $request = (new BatchCreateSitesRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchCreateSitesResponse $response */
        $response = $siteServiceClient->batchCreateSites($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 = SiteServiceClient::networkName('[NETWORK_CODE]');
    $formattedRequestsParent = SiteServiceClient::networkName('[NETWORK_CODE]');
    $requestsSiteUrl = '[URL]';

    batch_create_sites_sample($formattedParent, $formattedRequestsParent, $requestsSiteUrl);
} 

batchDeactivateSites

Deactivates a list of Site objects.

The async variant is SiteServiceClient::batchDeactivateSitesAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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.

Example
 use Google\Ads\AdManager\V1\BatchDeactivateSitesRequest;
use Google\Ads\AdManager\V1\BatchDeactivateSitesResponse;
use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent Format: `networks/{network_code}`
 *                                Please see {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $namesElement    The resource names of the `Site` objects to deactivate.
 */
function batch_deactivate_sites_sample(string $formattedParent, string $namesElement): void
{
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $names = [$namesElement,];
    $request = (new BatchDeactivateSitesRequest())
        ->setParent($formattedParent)
        ->setNames($names);

    // Call the API and handle any network failures.
    try {
        /** @var BatchDeactivateSitesResponse $response */
        $response = $siteServiceClient->batchDeactivateSites($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 = SiteServiceClient::networkName('[NETWORK_CODE]');
    $namesElement = '[NAMES]';

    batch_deactivate_sites_sample($formattedParent, $namesElement);
} 

batchSubmitSitesForApproval

Submits a list of Site objects for approval.

The async variant is SiteServiceClient::batchSubmitSitesForApprovalAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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.

Example
 use Google\Ads\AdManager\V1\BatchSubmitSitesForApprovalRequest;
use Google\Ads\AdManager\V1\BatchSubmitSitesForApprovalResponse;
use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent Format: `networks/{network_code}`
 *                                Please see {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $namesElement    The resource names of the `Site` objects to submit for approval.
 */
function batch_submit_sites_for_approval_sample(
    string $formattedParent,
    string $namesElement
): void {
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $names = [$namesElement,];
    $request = (new BatchSubmitSitesForApprovalRequest())
        ->setParent($formattedParent)
        ->setNames($names);

    // Call the API and handle any network failures.
    try {
        /** @var BatchSubmitSitesForApprovalResponse $response */
        $response = $siteServiceClient->batchSubmitSitesForApproval($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 = SiteServiceClient::networkName('[NETWORK_CODE]');
    $namesElement = '[NAMES]';

    batch_submit_sites_for_approval_sample($formattedParent, $namesElement);
} 

batchUpdateSites

API to batch update Site objects.

The async variant is SiteServiceClient::batchUpdateSitesAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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.

Example
 use Google\Ads\AdManager\V1\BatchUpdateSitesRequest;
use Google\Ads\AdManager\V1\BatchUpdateSitesResponse;
use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\Site;
use Google\Ads\AdManager\V1\UpdateSiteRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $formattedParent The parent resource where `Sites` will be updated.
 *                                Format: `networks/{network_code}`
 *                                The parent field in the UpdateSiteRequest must match this
 *                                field. Please see
 *                                {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $requestsSiteUrl The URL of the Site.
 */
function batch_update_sites_sample(string $formattedParent, string $requestsSiteUrl): void
{
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $requestsSite = (new Site())
        ->setUrl($requestsSiteUrl);
    $requestsUpdateMask = new FieldMask();
    $updateSiteRequest = (new UpdateSiteRequest())
        ->setSite($requestsSite)
        ->setUpdateMask($requestsUpdateMask);
    $requests = [$updateSiteRequest,];
    $request = (new BatchUpdateSitesRequest())
        ->setParent($formattedParent)
        ->setRequests($requests);

    // Call the API and handle any network failures.
    try {
        /** @var BatchUpdateSitesResponse $response */
        $response = $siteServiceClient->batchUpdateSites($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 = SiteServiceClient::networkName('[NETWORK_CODE]');
    $requestsSiteUrl = '[URL]';

    batch_update_sites_sample($formattedParent, $requestsSiteUrl);
} 

createSite

API to create a Site object.

The async variant is SiteServiceClient::createSiteAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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
Example
 use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\CreateSiteRequest;
use Google\Ads\AdManager\V1\Site;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedParent The parent resource where this `Site` will be created.
 *                                Format: `networks/{network_code}`
 *                                Please see {@see SiteServiceClient::networkName()} for help formatting this field.
 * @param string $siteUrl         The URL of the Site.
 */
function create_site_sample(string $formattedParent, string $siteUrl): void
{
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $site = (new Site())
        ->setUrl($siteUrl);
    $request = (new CreateSiteRequest())
        ->setParent($formattedParent)
        ->setSite($site);

    // Call the API and handle any network failures.
    try {
        /** @var Site $response */
        $response = $siteServiceClient->createSite($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 = SiteServiceClient::networkName('[NETWORK_CODE]');
    $siteUrl = '[URL]';

    create_site_sample($formattedParent, $siteUrl);
} 

getSite

API to retrieve a Site object.

The async variant is SiteServiceClient::getSiteAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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
Example
 use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\GetSiteRequest;
use Google\Ads\AdManager\V1\Site;
use Google\ApiCore\ApiException;

/**
 * @param string $formattedName The resource name of the Site.
 *                              Format: `networks/{network_code}/sites/{site_id}`
 *                              Please see {@see SiteServiceClient::siteName()} for help formatting this field.
 */
function get_site_sample(string $formattedName): void
{
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

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

    // Call the API and handle any network failures.
    try {
        /** @var Site $response */
        $response = $siteServiceClient->getSite($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 = SiteServiceClient::siteName('[NETWORK_CODE]', '[SITE]');

    get_site_sample($formattedName);
} 

listSites

API to retrieve a list of Site objects.

The async variant is SiteServiceClient::listSitesAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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
Example
 use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\ListSitesRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;

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

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

    // Call the API and handle any network failures.
    try {
        /** @var PagedListResponse $response */
        $response = $siteServiceClient->listSites($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 = SiteServiceClient::networkName('[NETWORK_CODE]');

    list_sites_sample($formattedParent);
} 

updateSite

API to update a Site object.

The async variant is SiteServiceClient::updateSiteAsync() .

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

A request to house fields associated with the call.

callOptions
array

Optional.

↳ retrySettings
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
Example
 use Google\Ads\AdManager\V1\Client\SiteServiceClient;
use Google\Ads\AdManager\V1\Site;
use Google\Ads\AdManager\V1\UpdateSiteRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;

/**
 * @param string $siteUrl The URL of the Site.
 */
function update_site_sample(string $siteUrl): void
{
    // Create a client.
    $siteServiceClient = new SiteServiceClient();

    // Prepare the request message.
    $site = (new Site())
        ->setUrl($siteUrl);
    $updateMask = new FieldMask();
    $request = (new UpdateSiteRequest())
        ->setSite($site)
        ->setUpdateMask($updateMask);

    // Call the API and handle any network failures.
    try {
        /** @var Site $response */
        $response = $siteServiceClient->updateSite($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
{
    $siteUrl = '[URL]';

    update_site_sample($siteUrl);
} 

batchCreateSitesAsync

Parameters
Name
Description
optionalArgs
array

batchDeactivateSitesAsync

Parameters
Name
Description
optionalArgs
array

batchSubmitSitesForApprovalAsync

Parameters
Name
Description
optionalArgs
array

batchUpdateSitesAsync

Parameters
Name
Description
optionalArgs
array

createSiteAsync

Parameters
Name
Description
optionalArgs
array

getSiteAsync

Parameters
Name
Description
optionalArgs
array

listSitesAsync

Parameters
Name
Description
optionalArgs
array

updateSiteAsync

Parameters
Name
Description
optionalArgs
array

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

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

Parameters
Name
Description
networkCode
string
site
string
Returns
Type
Description
string
The formatted site 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

  • network: networks/{network_code}
  • site: networks/{network_code}/sites/{site}

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.
Design a Mobile Site
View Site in Mobile | Classic
Share by: