البيانات الوصفية للرد
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تتولّى مكتبة برامج PHP تسجيل البيانات الوصفية للاستجابة، بما في ذلك رقم تعريف الطلب، تلقائيًا. بدلاً من ذلك، يمكنك الحصول على البيانات الوصفية للرد آليًا عند استدعاء طرق خدمة العميل من خلال ضبط المَعلمة الاختيارية withResponseMetadata
على true
.
بعد استدعاء طرق خدمة العميل، يمكنك الحصول على
GoogleAdsResponseMetadata
من عنصر ذي صلة، مثل عميل خدمة أو بث، وفقًا للطريقة التي تستدعيها. يحتوي هذا العنصر على getMetadata()
وgetRequestId()
،
اللذين يعرضان البيانات الوصفية للاستجابة ومعرّف الطلب الخاص باستدعاء واجهة برمجة التطبيقات، على التوالي.
تعرض الطريقة 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()
عملية استخراج معرّف الطلب من مصفوفة البيانات الوصفية، ما يوفّر عليك عناء تحليلها يدويًا.
توضّح الأقسام التالية كيفية استرداد GoogleAdsResponseMetadata
لكل طريقة.
SearchStream
للحصول على عنصر من GoogleAdsResponseMetadata
، استدعِ getResponseMetadata()
على عنصر stream:
$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
.
إنّ محتوى هذه الصفحة مرخّص بموجب ترخيص Creative Commons Attribution 4.0 ما لم يُنصّ على خلاف ذلك، ونماذج الرموز مرخّصة بموجب ترخيص Apache 2.0. للاطّلاع على التفاصيل، يُرجى مراجعة سياسات موقع Google Developers. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-27 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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`."]]