正在擷取物件
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
GoogleAdsService
是 Google Ads API 的統一物件擷取和報表服務。這項服務提供下列方法:
- 擷取物件的特定屬性。
- 根據日期範圍擷取物件的成效指標。
- 根據物件的屬性排序。
- 使用條件指出要在回應中傳回哪些物件。
- 限制傳回的物件數量。
GoogleAdsService
可以透過下列兩種方式傳回結果:
進一步瞭解分頁與串流。
提出要求
搜尋方法需要 SearchGoogleAdsRequest
,其中包含下列屬性:
- A
customer_id
- Google Ads 查詢語言
query
,指出要查詢的資源、要擷取的屬性、區隔和指標,以及用於限制傳回哪些物件的條件
- (僅限
GoogleAdsService.Search
) 使用分頁時,可選用 page_token
擷取下一批結果。
如要進一步瞭解 Google Ads 查詢語言,請參閱 Google Ads 查詢語言指南。
處理回覆
GoogleAdsService
會傳回 GoogleAdsRow
物件的清單。
每個 GoogleAdsRow
都代表查詢傳回的物件,並包含一組屬性,這些屬性會根據 SELECT
子句中要求的欄位填入。系統不會在回應的 GoogleAdsRow
物件中填入未列於 SELECT
子句中的屬性。
舉例來說,雖然 ad_group_criterion
具有 status
屬性,但如果查詢的 SELECT
子句未包含 ad_group_criterion.status
,則系統不會在查詢的回應中填入資料列 ad_group_criterion
屬性的 status
欄位。同樣地,如果 SELECT
子句未包含 campaign
資源中的任何欄位,系統就不會填入資料列的 campaign
屬性。
每個 GoogleAdsRow
的屬性和指標可能與同一結果集中的其他資料列不同,因此資料列應視為物件,而非表格的固定資料列。
UNKNOWN 列舉類型
如果資源傳回的類型為 UNKNOWN
,表示該 API 版本不完全支援這類資源。這些資源可能是透過其他介面 (例如 Google Ads 使用者介面) 建立。當資源類型為 UNKNOWN
時,您可以選取指標,但無法透過 API 變更資源。舉例來說,UI 中導入了新的廣告活動或廣告,但您查詢的 API 版本不支援。
請注意以下幾點:
UNKNOWN
類型的資源日後可能會支援,也可能無限期維持 UNKNOWN
狀態。
- 類型為
UNKNOWN
的新物件隨時可能會出現。這些物件可向後相容,因為列舉值已可使用。這項異動會一併推出「資源」,方便您準確掌握帳戶狀況。如果透過其他介面在帳戶中進行新活動,或資源不再受支援,系統可能會顯示 UNKNOWN
資源。
UNKNOWN
資源可以附加詳細指標,供您查詢。
UNKNOWN
資源通常會完整顯示在 Google Ads 使用者介面中。
UNKNOWN
資源通常無法變動。
區隔
回應會針對下列各項的組合,各包含一個 GoogleAdsRow
:
FROM
子句中指定的主要資源例項
- 每個所選
segment
欄位的值
舉例來說,如果查詢選取 FROM campaign
,且 SELECT
子句中包含 segments.ad_network_type
和 segments.date
,則回應會針對下列各項的每個組合包含一個資料列:
campaign
segments.ad_network_type
segments.date
系統會根據主要資源的每個例項隱含地區隔結果,而不是根據所選個別欄位的值。例如:
SELECT campaign.status, metrics.impressions
FROM campaign
WHERE segments.date DURING LAST_14_DAYS
因此每個廣告活動會有一列,而非 campaign.status
欄位中每個不重複的值各有一列。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-26 (世界標準時間)。
[null,null,["上次更新時間:2025-08-26 (世界標準時間)。"],[[["\u003cp\u003eGoogle Ads API's \u003ccode\u003eGoogleAdsService\u003c/code\u003e enables retrieval of object attributes, performance stats, and implements ordering, conditions, and limits for streamlined data access.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGoogleAdsService\u003c/code\u003e offers two response methods: \u003ccode\u003eSearchStream\u003c/code\u003e for efficient handling of large datasets and \u003ccode\u003eSearch\u003c/code\u003e for manageable, paginated results.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eGoogleAdsService.Search\u003c/code\u003e requests require \u003ccode\u003ecustomer_id\u003c/code\u003e, Google Ads Query Language \u003ccode\u003equery\u003c/code\u003e, and optional pagination parameters (\u003ccode\u003epage_size\u003c/code\u003e, \u003ccode\u003epage_token\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eResponses comprise \u003ccode\u003eGoogleAdsRow\u003c/code\u003e objects, reflecting queried object attributes and metrics as specified in the \u003ccode\u003eSELECT\u003c/code\u003e clause.\u003c/p\u003e\n"],["\u003cp\u003eResources returned with an \u003ccode\u003eUNKNOWN\u003c/code\u003e type are not fully supported in that API version, might have been created through other interfaces, and are generally not mutable.\u003c/p\u003e\n"]]],[],null,["# Retrieving objects\n\n| **Objective:** Understand how to retrieve objects and performance stats using [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService). For reporting concepts, see the [reporting guides](/google-ads/api/docs/reporting/overview).\n\nThe [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService) is the unified object\nretrieval and reporting service of the Google Ads API. The service has methods that:\n\n- Retrieve specific attributes of objects.\n- Retrieve performance metrics for objects based on a date range.\n- Order objects based on their attributes.\n- Use conditions to indicate which objects you want returned in the response.\n- Limit the number of objects returned.\n\nThe [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService) can return results in\ntwo ways:\n\n- [`GoogleAdsService.SearchStream`](/google-ads/api/reference/rpc/v21/GoogleAdsService/SearchStream) returns all rows in a single streaming response which is more efficient for large (greater than 10,000 rows) result sets. This might be more appropriate if your batch application wants to download as much data as fast as possible.\n- [`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) breaks up large responses into manageable pages of results. This could be more appropriate if your interactive application displays a page of results at a time.\n\nLearn more about [paging versus streaming](/google-ads/api/docs/reporting/streaming).\n\nMake a request\n--------------\n\nThe search method requires a\n[`SearchGoogleAdsRequest`](/google-ads/api/reference/rpc/v21/SearchGoogleAdsRequest), which consists\nof the following attributes:\n\n- A `customer_id`\n- A Google Ads Query Language `query` that indicates which resource to query, the attributes, segments, and metrics to retrieve, and the conditions to use to restrict which objects are returned\n- ([`GoogleAdsService.Search`](/google-ads/api/reference/rpc/v21/GoogleAdsService/Search) only) An optional `page_token` to retrieve the next batch of results when using [paging](/google-ads/api/docs/reporting/paging).\n\nFor more information on the Google Ads Query Language, check out the [Google Ads Query Language\nguide](/google-ads/api/docs/query/overview).\n\nProcess a response\n------------------\n\nThe [`GoogleAdsService`](/google-ads/api/reference/rpc/v21/GoogleAdsService) returns a list of\n[`GoogleAdsRow`](/google-ads/api/reference/rpc/v21/GoogleAdsRow) objects.\n\nEach `GoogleAdsRow` represents an object returned by a query, and consists of a\nset of attributes that are populated based on the fields requested in the\n`SELECT` clause. Attributes not included in the `SELECT` clause are not\npopulated on the `GoogleAdsRow` objects in the response.\n\nFor example, although an `ad_group_criterion` has a `status` attribute, the\n`status` field of the row's `ad_group_criterion` attribute is not populated in a\nresponse for a query where the `SELECT` clause does not include\n`ad_group_criterion.status`. Similarly, the `campaign` attribute of the row is\nnot populated if the `SELECT` clause does not include any fields from the\n`campaign` resource.\n\nEach `GoogleAdsRow` can have different attributes and metrics from another row\nin the same result set; so the rows should be viewed as objects rather than\nfixed rows of a table.\n\nUNKNOWN enum types\n------------------\n\nResources that are returned with a type of `UNKNOWN` are not fully supported in\nthat API version. These resources could have been created through other\ninterfaces such as the Google Ads UI. You can select metrics when a resource has a\ntype of `UNKNOWN`, but you cannot mutate the resource through the API. An\nexample of this would be a new campaign or ad being introduced in the UI, but\nnot supported in the API version you are querying.\n\nHere are some considerations to keep in mind:\n\n- A resource with an `UNKNOWN` type can be supported later or stay `UNKNOWN` indefinitely.\n- New objects with type `UNKNOWN` can appear at any time. These objects are backward compatible because the enum value is already available. Resources are introduced with this change as they're available so that you have an accurate view of your account. The `UNKNOWN` resource can appear due to new activities in your account through other interfaces, or when a resource is no longer supported.\n- `UNKNOWN` resources can have detailed metrics attached to them that are queryable.\n- `UNKNOWN` resources are typically fully visible in the Google Ads UI.\n- `UNKNOWN` resources generally cannot be mutated.\n\nSegmentation\n------------\n\nThe response would contain one `GoogleAdsRow` for each combination of the\nfollowing:\n\n- Instance of the main resource specified in the `FROM` clause\n- Value of each selected `segment` field\n\nFor example, the response for a query that selects `FROM campaign` and has\n`segments.ad_network_type` and `segments.date` in the `SELECT` clause would\ncontain one row for each combination of the following:\n\n- `campaign`\n- `segments.ad_network_type`\n- `segments.date`\n\nResults are implicitly segmented by each instance of the main resource, not by\nthe values of the individual fields selected. For example, \n\n SELECT campaign.status, metrics.impressions\n FROM campaign\n WHERE segments.date DURING LAST_14_DAYS\n\nresults in one row per **campaign** , not one row per distinct value of the\n`campaign.status` field."]]