有兴趣分享您对 Google Ads API 的反馈吗?
注册即可获邀参与用户调研!
可选请求标头
在请求方法中使用任何可选字段时,必须在方法之外构建请求消息,并将其作为单个参数传入。
可选请求标头(例如 GoogleAdsService.Search
方法中的 validate_only
标头)不会以关键字参数的形式出现在方法签名中,因此必须直接在请求消息中进行设置。
如需确定请求对象字段是必需字段还是可选字段,您可以参考服务的 protobuf 定义,并查找包含注解 [(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)
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-21。
[null,null,["最后更新时间 (UTC):2024-11-21。"],[[["When using optional fields in Google Ads API requests, construct the request message separately and pass it as a single parameter to the method."],["Optional request headers like `validate_only` are set directly on the request message, not as keyword parameters in the method signature."],["You can identify required or optional request fields by checking the protobuf definitions and looking for the `[(google.api.field_behavior) = REQUIRED]` annotation."],["To 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."]]],[]]