AI-generated Key Takeaways
-
The PHP client library logs response metadata, including a request ID, by default.
-
You can programmatically obtain response metadata by setting the optional parameter
withResponseMetadatatotruewhen calling client service methods. -
After calling client service methods, you can retrieve
GoogleAdsResponseMetadatafrom a relevant object, like a service client or a stream, which contains methods to get the full response metadata and the request ID. -
For
SearchStream, callgetResponseMetadata()on the stream object to getGoogleAdsResponseMetadata. -
For
Searchand other mutate methods, callgetResponseMetadata()on the client object to getGoogleAdsResponseMetadata.
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\V22\GoogleAdsResponseMetadata)#51 (1) {
["metadata":"Google\Ads\GoogleAds\Lib\V22\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.