在要求方法中使用任何選用欄位時,要求訊息必須在方法外建構,並以單一參數傳入。
選用要求標頭 (例如 GoogleAdsService.Search
方法中的 page_size
和 validate_only
標頭) 並非以關鍵字參數的形式出現在方法簽章中,因此您必須直接在要求訊息中設定這些標頭。
如要判斷要求物件欄位是否為必要欄位,您可以參照服務的 protobuf 定義,並尋找包含註解 [(google.api.field_behavior) =
REQUIRED]
的欄位。
以下範例說明如何在 GoogleAdsService.Search
要求中設定 page_size
和 validate_only
欄位:
request = client.get_type("SearchGoogleAdsRequest")
request.customer_id = customer_id
request.query = query
request.page_size = 10000
request.validate_only = True
response = googleads_service.search(request=request)