Response Metadata

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.

Here is an example of sending a query to GoogleAdsService.SearchStream() and setting withResponseMetadata to true:

[$response, $metadata] = $googleAdsServiceClient->searchStream(
    $customerId,
    $query,
    ['withResponseMetadata' => true]
);

An array is returned, with $response consisting of the query's results from SearchGoogleAdsStreamResponse.

The second member in the array, $metadata, holds the response metadata in the metadata field, which itself is an array:

object(Google\Ads\GoogleAds\Lib\V16\GoogleAdsResponseMetadata)#51 (1) {
  ["metadata":"Google\Ads\GoogleAds\Lib\V16\GoogleAdsResponseMetadata":private]=>
  array(17) {
    ["content-disposition"]=>
    array(1) {
      [0]=>
      string(10) "attachment"
    }
    ["request-id"]=>
    array(1) {
      [0]=>
      string(22) "REQUEST_ID"
    }
    ...
  }
}

You can retrieve the request ID from the request-id key, similarly to using GoogleAdsResponseMetadata::getRequestId().