選擇性要求標頭

在要求方法中使用任何選用欄位時,要求訊息必須在方法外部建構,並以單一參數的形式傳入。

選用要求標頭 (例如 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)