The PHP client library logs the response
metadata, including a request ID, by default. Alternatively, you can obtain the
response metadata programmatically when calling client service methods by
setting the optional parameter withResponseMetadata
to true
.
After you call client service methods, you can then obtain
GoogleAdsResponseMetadata
,
from a relevant object, like a service client or a stream, according to the
method you call. This object contains getMetadata()
and getRequestId()
,
which return response metadata and the request ID of the API call, respectively.
The getMetadata()
method returns an array that looks like this:
object(Google\Ads\GoogleAds\Lib\V17\GoogleAdsResponseMetadata)#51 (1) {
["metadata":"Google\Ads\GoogleAds\Lib\V17\GoogleAdsResponseMetadata":private]=>
array(17) {
["content-disposition"]=>
array(1) {
[0]=>
string(10) "attachment"
}
["request-id"]=>
array(1) {
[0]=>
string(22) "REQUEST_ID"
}
...
}
}
The getRequestId()
method simplifies the process of extracting the request ID
from the metadata array, saving you the effort of manually parsing it.
The following sections explain how to retrieve GoogleAdsResponseMetadata
for
each method.
SearchStream
To obtain an object of GoogleAdsResponseMetadata
, call getResponseMetadata()
on the stream object:
$stream = $googleAdsServiceClient->searchStream(
SearchGoogleAdsStreamRequest::build($customerId, $query),
['withResponseMetadata' => true]
);
// Prints the request ID.
print $stream->getResponseMetadata()->getRequestId() . PHP_EOL;
The $stream->getResponseMetadata()
is an object of
GoogleAdsResponseMetadata
.
Search and other mutate methods
To obtain an object of GoogleAdsResponseMetadata
, call getResponseMetadata()
on the client object:
// Retrieves objects.
$response = $googleAdsServiceClient->search(
SearchGoogleAdsRequest::build($customerId, $query),
['withResponseMetadata' => true]
);
// Prints the request ID.
print $googleAdsServiceClient->getResponseMetadata()->getRequestId() . PHP_EOL;
// Mutates campaigns.
$response = $campaignServiceClient->mutateCampaigns(
MutateCampaignsRequest::build($customerId, $campaignOperations),
['withResponseMetadata' => true]
);
// Prints the request ID.
print $campaignServiceClient->getResponseMetadata()->getRequestId() . PHP_EOL;
The $campaignServiceClient->getResponseMetadata()
and
$googleAdsServiceClient->getResponseMetadata()
are an object of
GoogleAdsResponseMetadata
.