レスポンスのメタデータ
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
PHP クライアント ライブラリは、デフォルトでリクエスト ID などのレスポンス メタデータをログに記録します。または、オプション パラメータ withResponseMetadata
を true
に設定してクライアント サービス メソッドを呼び出すときに、レスポンス メタデータをプログラムで取得することもできます。
クライアント サービス メソッドを呼び出すと、呼び出すメソッドに応じて、サービス クライアントやストリームなどの関連オブジェクトから GoogleAdsResponseMetadata
を取得できます。このオブジェクトには getMetadata()
と getRequestId()
が含まれています。これらはそれぞれ、レスポンス メタデータと API 呼び出しのリクエスト ID を返します。getMetadata()
メソッドは次のような配列を返します。
object(Google\Ads\GoogleAds\Lib\V21\GoogleAdsResponseMetadata)#51 (1) {
["metadata":"Google\Ads\GoogleAds\Lib\V21\GoogleAdsResponseMetadata":private]=>
array(17) {
["content-disposition"]=>
array(1) {
[0]=>
string(10) "attachment"
}
["request-id"]=>
array(1) {
[0]=>
string(22) "REQUEST_ID"
}
...
}
}
getRequestId()
メソッドを使用すると、メタデータ配列からリクエスト ID を抽出するプロセスが簡素化され、手動で解析する手間が省けます。
以降のセクションでは、各メソッドの GoogleAdsResponseMetadata
を取得する方法について説明します。
SearchStream
GoogleAdsResponseMetadata
のオブジェクトを取得するには、stream オブジェクトで getResponseMetadata()
を呼び出します。
$stream = $googleAdsServiceClient->searchStream(
SearchGoogleAdsStreamRequest::build($customerId, $query),
['withResponseMetadata' => true]
);
// Prints the request ID.
print $stream->getResponseMetadata()->getRequestId() . PHP_EOL;
$stream->getResponseMetadata()
は GoogleAdsResponseMetadata
のオブジェクトです。
検索とその他の変更メソッド
GoogleAdsResponseMetadata
のオブジェクトを取得するには、クライアント オブジェクトで getResponseMetadata()
を呼び出します。
// 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;
$campaignServiceClient->getResponseMetadata()
と $googleAdsServiceClient->getResponseMetadata()
は GoogleAdsResponseMetadata
のオブジェクトです。
特に記載のない限り、このページのコンテンツはクリエイティブ・コモンズの表示 4.0 ライセンスにより使用許諾されます。コードサンプルは Apache 2.0 ライセンスにより使用許諾されます。詳しくは、Google Developers サイトのポリシーをご覧ください。Java は Oracle および関連会社の登録商標です。
最終更新日 2025-09-05 UTC。
[null,null,["最終更新日 2025-09-05 UTC。"],[[["\u003cp\u003eThe PHP client library automatically logs response metadata, including a request ID.\u003c/p\u003e\n"],["\u003cp\u003eYou can programmatically access response metadata, including the request ID, using the \u003ccode\u003ewithResponseMetadata\u003c/code\u003e parameter and the \u003ccode\u003eGoogleAdsResponseMetadata\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGoogleAdsResponseMetadata\u003c/code\u003e object provides methods like \u003ccode\u003egetMetadata()\u003c/code\u003e to retrieve detailed metadata and \u003ccode\u003egetRequestId()\u003c/code\u003e for easy access to the request ID.\u003c/p\u003e\n"],["\u003cp\u003eDepending on the method used (SearchStream, Search, or other mutate methods), you can retrieve the \u003ccode\u003eGoogleAdsResponseMetadata\u003c/code\u003e object from either the stream or the client object.\u003c/p\u003e\n"]]],[],null,["# Response Metadata\n\nThe PHP client library [logs](/google-ads/api/docs/client-libs/php/logging) the response\nmetadata, including a request ID, by default. Alternatively, you can obtain the\nresponse metadata programmatically when calling client service methods by\nsetting the optional parameter `withResponseMetadata` to `true`.\n\nAfter you call client service methods, you can then obtain\n[`GoogleAdsResponseMetadata`](//github.com/googleads/google-ads-php/blob/main/src/Google/Ads/GoogleAds/Lib/V21/GoogleAdsResponseMetadata.php),\nfrom a relevant object, like a service client or a stream, according to the\nmethod you call. This object contains `getMetadata()` and `getRequestId()`,\nwhich return response metadata and the request ID of the API call, respectively.\nThe `getMetadata()` method returns an array that looks like this: \n\n object(Google\\Ads\\GoogleAds\\Lib\\V21\\GoogleAdsResponseMetadata)#51 (1) {\n [\"metadata\":\"Google\\Ads\\GoogleAds\\Lib\\V21\\GoogleAdsResponseMetadata\":private]=\u003e\n array(17) {\n [\"content-disposition\"]=\u003e\n array(1) {\n [0]=\u003e\n string(10) \"attachment\"\n }\n \\[\"request-id\"\\]=\\\u003e\n array(1) {\n \\[0\\]=\\\u003e\n string(22) \"REQUEST_ID\"\n }\n ...\n }\n }\n\nThe `getRequestId()` method simplifies the process of extracting the request ID\nfrom the metadata array, saving you the effort of manually parsing it.\n\nThe following sections explain how to retrieve `GoogleAdsResponseMetadata` for\neach method.\n\nSearchStream\n------------\n\nTo obtain an object of `GoogleAdsResponseMetadata`, call `getResponseMetadata()`\non the **stream** object: \n\n $stream = $googleAdsServiceClient-\u003esearchStream(\n SearchGoogleAdsStreamRequest::build($customerId, $query),\n ['withResponseMetadata' =\u003e true]\n );\n\n // Prints the request ID.\n print $stream-\u003egetResponseMetadata()-\u003egetRequestId() . PHP_EOL;\n\nThe `$stream-\u003egetResponseMetadata()` is an object of\n`GoogleAdsResponseMetadata`.\n\nSearch and other mutate methods\n-------------------------------\n\nTo obtain an object of `GoogleAdsResponseMetadata`, call `getResponseMetadata()`\non the **client** object: \n\n // Retrieves objects.\n $response = $googleAdsServiceClient-\u003esearch(\n SearchGoogleAdsRequest::build($customerId, $query),\n ['withResponseMetadata' =\u003e true]\n );\n\n // Prints the request ID.\n print $googleAdsServiceClient-\u003egetResponseMetadata()-\u003egetRequestId() . PHP_EOL;\n\n // Mutates campaigns.\n $response = $campaignServiceClient-\u003emutateCampaigns(\n MutateCampaignsRequest::build($customerId, $campaignOperations),\n ['withResponseMetadata' =\u003e true]\n );\n\n // Prints the request ID.\n print $campaignServiceClient-\u003egetResponseMetadata()-\u003egetRequestId() . PHP_EOL;\n\nThe `$campaignServiceClient-\u003egetResponseMetadata()` and\n`$googleAdsServiceClient-\u003egetResponseMetadata()` are an object of\n`GoogleAdsResponseMetadata`."]]