वैकल्पिक अनुरोध के हेडर
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
अनुरोध के तरीके पर किसी भी ज़रूरी फ़ील्ड का इस्तेमाल करते समय, अनुरोध मैसेज को तरीके के बाहर बनाया जाना चाहिए और एक पैरामीटर के तौर पर पास किया जाना चाहिए.
वैकल्पिक अनुरोध हेडर, जैसे कि GoogleAdsService.Search
तरीके में validate_only
हेडर, कीवर्ड पैरामीटर के तौर पर मेथड सिग्नेचर में मौजूद नहीं होते. इसलिए, उन्हें सीधे अनुरोध मैसेज पर सेट किया जाना चाहिए.
यह तय करने के लिए कि अनुरोध ऑब्जेक्ट फ़ील्ड ज़रूरी है या नहीं, सेवाओं के लिए प्रोटोबुक की परिभाषाएं देखें. साथ ही, ऐसे फ़ील्ड खोजें जिनमें एनोटेशन [(google.api.field_behavior) =
REQUIRED]
हो.
यहां एक उदाहरण दिया गया है, जिसमें GoogleAdsService.Search
अनुरोध पर, वैकल्पिक validate_only
फ़ील्ड को सेट किया गया है:
request = client.get_type("SearchGoogleAdsRequest")
request.customer_id = customer_id
request.query = query
request.validate_only = True
response = googleads_service.search(request=request)
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-27 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 2025-08-27 (UTC) को अपडेट किया गया."],[[["\u003cp\u003eWhen using optional fields in Google Ads API requests, construct the request message separately and pass it as a single parameter to the method.\u003c/p\u003e\n"],["\u003cp\u003eOptional request headers like \u003ccode\u003evalidate_only\u003c/code\u003e are set directly on the request message, not as keyword parameters in the method signature.\u003c/p\u003e\n"],["\u003cp\u003eYou can identify required or optional request fields by checking the protobuf definitions and looking for the \u003ccode\u003e[(google.api.field_behavior) = REQUIRED]\u003c/code\u003e annotation.\u003c/p\u003e\n"],["\u003cp\u003eTo use optional fields, create an instance of the request message type, populate its fields including the optional ones, and then pass it to the API method.\u003c/p\u003e\n"]]],[],null,["# Optional request headers\n\nWhen using any\n[optional fields](//protobuf.dev/programming-guides/proto3/#field-labels) on a\nrequest method, the request message must be constructed outside of the\nmethod and passed in as a single parameter.\n\nOptional request headers, for example the\n[`validate_only`](/google-ads/api/reference/rpc/v21/SearchGoogleAdsRequest#validate_only) header in\nthe [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) method,\nare not present in the method signature as keyword parameters, so they must be\nset on the request message directly.\n\nTo determine if a request object field is required or optional, you can\nreference the [protobuf definitions for\nservices](//github.com/googleapis/googleapis/tree/master/google/ads/googleads/v21/services)\nand look for fields that contain the annotation `[(google.api.field_behavior) =\nREQUIRED]`.\n\nHere's an example that sets the optional `validate_only` field\non a [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) request: \n\n request = client.get_type(\"SearchGoogleAdsRequest\")\n request.customer_id = customer_id\n request.query = query\n request.validate_only = True\n\n response = googleads_service.search(request=request)"]]