Reference documentation and code samples for the Google Ads Ad Manager V1 Client class PlacementServiceClient.
Service Description: Provides methods for handling Placement
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 \ ClientMethods
__construct
Constructor.
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\PlacementServiceClient; $creds = new ServiceAccountCredentials($scopes, $json); $options = new PlacementServiceClient(['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'.
batchActivatePlacements
Activates a list of Placement
objects.
The async variant is PlacementServiceClient::batchActivatePlacementsAsync() .
request
Google\Ads\AdManager\V1\BatchActivatePlacementsRequest
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.
use Google\Ads\AdManager\V1\BatchActivatePlacementsRequest;
use Google\Ads\AdManager\V1\BatchActivatePlacementsResponse;
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $formattedNamesElement The names of the `Placement` objects to activate.
* Format: `networks/{network_code}/placements/{placement_id}`
* Please see {@see PlacementServiceClient::placementName()} for help formatting this field.
*/
function batch_activate_placements_sample(
string $formattedParent,
string $formattedNamesElement
): void {
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$formattedNames = [$formattedNamesElement,];
$request = (new BatchActivatePlacementsRequest())
->setParent($formattedParent)
->setNames($formattedNames);
// Call the API and handle any network failures.
try {
/** @var BatchActivatePlacementsResponse $response */
$response = $placementServiceClient->batchActivatePlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$formattedNamesElement = PlacementServiceClient::placementName('[NETWORK_CODE]', '[PLACEMENT]');
batch_activate_placements_sample($formattedParent, $formattedNamesElement);
}
batchArchivePlacements
Archives a list of Placement
objects.
The async variant is PlacementServiceClient::batchArchivePlacementsAsync() .
request
Google\Ads\AdManager\V1\BatchArchivePlacementsRequest
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.
use Google\Ads\AdManager\V1\BatchArchivePlacementsRequest;
use Google\Ads\AdManager\V1\BatchArchivePlacementsResponse;
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $formattedNamesElement The names of the `Placement` objects to archive.
* Format: `networks/{network_code}/placements/{placement_id}`
* Please see {@see PlacementServiceClient::placementName()} for help formatting this field.
*/
function batch_archive_placements_sample(
string $formattedParent,
string $formattedNamesElement
): void {
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$formattedNames = [$formattedNamesElement,];
$request = (new BatchArchivePlacementsRequest())
->setParent($formattedParent)
->setNames($formattedNames);
// Call the API and handle any network failures.
try {
/** @var BatchArchivePlacementsResponse $response */
$response = $placementServiceClient->batchArchivePlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$formattedNamesElement = PlacementServiceClient::placementName('[NETWORK_CODE]', '[PLACEMENT]');
batch_archive_placements_sample($formattedParent, $formattedNamesElement);
}
batchCreatePlacements
API to batch create Placement
objects.
The async variant is PlacementServiceClient::batchCreatePlacementsAsync() .
request
Google\Ads\AdManager\V1\BatchCreatePlacementsRequest
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.
use Google\Ads\AdManager\V1\BatchCreatePlacementsRequest;
use Google\Ads\AdManager\V1\BatchCreatePlacementsResponse;
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\CreatePlacementRequest;
use Google\Ads\AdManager\V1\Placement;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent The parent resource where the `Placement`s will be created.
* Format: `networks/{network_code}`
* The parent field in the CreatePlacementRequest messages match this
* field. Please see
* {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $formattedRequestsParent The parent resource where this `Placement` will be created.
* Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $requestsPlacementDisplayName The display name of the placement. This attribute has a maximum
* length of 255 characters.
*/
function batch_create_placements_sample(
string $formattedParent,
string $formattedRequestsParent,
string $requestsPlacementDisplayName
): void {
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$requestsPlacement = (new Placement())
->setDisplayName($requestsPlacementDisplayName);
$createPlacementRequest = (new CreatePlacementRequest())
->setParent($formattedRequestsParent)
->setPlacement($requestsPlacement);
$requests = [$createPlacementRequest,];
$request = (new BatchCreatePlacementsRequest())
->setParent($formattedParent)
->setRequests($requests);
// Call the API and handle any network failures.
try {
/** @var BatchCreatePlacementsResponse $response */
$response = $placementServiceClient->batchCreatePlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$formattedRequestsParent = PlacementServiceClient::networkName('[NETWORK_CODE]');
$requestsPlacementDisplayName = '[DISPLAY_NAME]';
batch_create_placements_sample(
$formattedParent,
$formattedRequestsParent,
$requestsPlacementDisplayName
);
}
batchDeactivatePlacements
Deactivates a list of Placement
objects.
The async variant is PlacementServiceClient::batchDeactivatePlacementsAsync() .
request
Google\Ads\AdManager\V1\BatchDeactivatePlacementsRequest
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.
use Google\Ads\AdManager\V1\BatchDeactivatePlacementsRequest;
use Google\Ads\AdManager\V1\BatchDeactivatePlacementsResponse;
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $formattedNamesElement The names of the `Placement` objects to deactivate.
* Format: `networks/{network_code}/placements/{placement_id}`
* Please see {@see PlacementServiceClient::placementName()} for help formatting this field.
*/
function batch_deactivate_placements_sample(
string $formattedParent,
string $formattedNamesElement
): void {
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$formattedNames = [$formattedNamesElement,];
$request = (new BatchDeactivatePlacementsRequest())
->setParent($formattedParent)
->setNames($formattedNames);
// Call the API and handle any network failures.
try {
/** @var BatchDeactivatePlacementsResponse $response */
$response = $placementServiceClient->batchDeactivatePlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$formattedNamesElement = PlacementServiceClient::placementName('[NETWORK_CODE]', '[PLACEMENT]');
batch_deactivate_placements_sample($formattedParent, $formattedNamesElement);
}
batchUpdatePlacements
API to batch update Placement
objects.
The async variant is PlacementServiceClient::batchUpdatePlacementsAsync() .
request
Google\Ads\AdManager\V1\BatchUpdatePlacementsRequest
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.
use Google\Ads\AdManager\V1\BatchUpdatePlacementsRequest;
use Google\Ads\AdManager\V1\BatchUpdatePlacementsResponse;
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\Placement;
use Google\Ads\AdManager\V1\UpdatePlacementRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
/**
* @param string $formattedParent The parent resource where `Placements` will be updated.
* Format: `networks/{network_code}`
* The parent field in the UpdatePlacementsRequest must match this
* field. Please see
* {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $requestsPlacementDisplayName The display name of the placement. This attribute has a maximum
* length of 255 characters.
*/
function batch_update_placements_sample(
string $formattedParent,
string $requestsPlacementDisplayName
): void {
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$requestsPlacement = (new Placement())
->setDisplayName($requestsPlacementDisplayName);
$requestsUpdateMask = new FieldMask();
$updatePlacementRequest = (new UpdatePlacementRequest())
->setPlacement($requestsPlacement)
->setUpdateMask($requestsUpdateMask);
$requests = [$updatePlacementRequest,];
$request = (new BatchUpdatePlacementsRequest())
->setParent($formattedParent)
->setRequests($requests);
// Call the API and handle any network failures.
try {
/** @var BatchUpdatePlacementsResponse $response */
$response = $placementServiceClient->batchUpdatePlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$requestsPlacementDisplayName = '[DISPLAY_NAME]';
batch_update_placements_sample($formattedParent, $requestsPlacementDisplayName);
}
createPlacement
API to create an Placement
object.
The async variant is PlacementServiceClient::createPlacementAsync() .
request
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.
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\CreatePlacementRequest;
use Google\Ads\AdManager\V1\Placement;
use Google\ApiCore\ApiException;
/**
* @param string $formattedParent The parent resource where this `Placement` will be created.
* Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
* @param string $placementDisplayName The display name of the placement. This attribute has a maximum
* length of 255 characters.
*/
function create_placement_sample(string $formattedParent, string $placementDisplayName): void
{
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$placement = (new Placement())
->setDisplayName($placementDisplayName);
$request = (new CreatePlacementRequest())
->setParent($formattedParent)
->setPlacement($placement);
// Call the API and handle any network failures.
try {
/** @var Placement $response */
$response = $placementServiceClient->createPlacement($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
$placementDisplayName = '[DISPLAY_NAME]';
create_placement_sample($formattedParent, $placementDisplayName);
}
getPlacement
API to retrieve a Placement
object.
The async variant is PlacementServiceClient::getPlacementAsync() .
request
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.
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\GetPlacementRequest;
use Google\Ads\AdManager\V1\Placement;
use Google\ApiCore\ApiException;
/**
* @param string $formattedName The resource name of the Placement.
* Format: `networks/{network_code}/placements/{placement_id}`
* Please see {@see PlacementServiceClient::placementName()} for help formatting this field.
*/
function get_placement_sample(string $formattedName): void
{
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$request = (new GetPlacementRequest())
->setName($formattedName);
// Call the API and handle any network failures.
try {
/** @var Placement $response */
$response = $placementServiceClient->getPlacement($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 = PlacementServiceClient::placementName('[NETWORK_CODE]', '[PLACEMENT]');
get_placement_sample($formattedName);
}
listPlacements
API to retrieve a list of Placement
objects.
The async variant is PlacementServiceClient::listPlacementsAsync() .
request
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.
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\ListPlacementsRequest;
use Google\ApiCore\ApiException;
use Google\ApiCore\PagedListResponse;
/**
* @param string $formattedParent The parent, which owns this collection of Placements.
* Format: `networks/{network_code}`
* Please see {@see PlacementServiceClient::networkName()} for help formatting this field.
*/
function list_placements_sample(string $formattedParent): void
{
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$request = (new ListPlacementsRequest())
->setParent($formattedParent);
// Call the API and handle any network failures.
try {
/** @var PagedListResponse $response */
$response = $placementServiceClient->listPlacements($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 = PlacementServiceClient::networkName('[NETWORK_CODE]');
list_placements_sample($formattedParent);
}
updatePlacement
API to update an Placement
object.
The async variant is PlacementServiceClient::updatePlacementAsync() .
request
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.
use Google\Ads\AdManager\V1\Client\PlacementServiceClient;
use Google\Ads\AdManager\V1\Placement;
use Google\Ads\AdManager\V1\UpdatePlacementRequest;
use Google\ApiCore\ApiException;
use Google\Protobuf\FieldMask;
/**
* @param string $placementDisplayName The display name of the placement. This attribute has a maximum
* length of 255 characters.
*/
function update_placement_sample(string $placementDisplayName): void
{
// Create a client.
$placementServiceClient = new PlacementServiceClient();
// Prepare the request message.
$placement = (new Placement())
->setDisplayName($placementDisplayName);
$updateMask = new FieldMask();
$request = (new UpdatePlacementRequest())
->setPlacement($placement)
->setUpdateMask($updateMask);
// Call the API and handle any network failures.
try {
/** @var Placement $response */
$response = $placementServiceClient->updatePlacement($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
{
$placementDisplayName = '[DISPLAY_NAME]';
update_placement_sample($placementDisplayName);
}
batchActivatePlacementsAsync
optionalArgs
array
batchArchivePlacementsAsync
optionalArgs
array
batchCreatePlacementsAsync
optionalArgs
array
batchDeactivatePlacementsAsync
optionalArgs
array
batchUpdatePlacementsAsync
optionalArgs
array
createPlacementAsync
optionalArgs
array
getPlacementAsync
listPlacementsAsync
optionalArgs
array
updatePlacementAsync
optionalArgs
array
static::adUnitName
Formats a string containing the fully-qualified path to represent a ad_unit resource.
networkCode
string
adUnit
string
string
static::networkName
Formats a string containing the fully-qualified path to represent a network resource.
networkCode
string
string
static::placementName
Formats a string containing the fully-qualified path to represent a placement resource.
networkCode
string
placement
string
string
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
- adUnit: networks/{network_code}/adUnits/{ad_unit}
- network: networks/{network_code}
- placement: networks/{network_code}/placements/{placement}
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.
formattedName
string
The formatted name string
template
?string
Optional name of template to match
array

