查詢公用程式
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
使用 API 時,如要擷取 proto 類別的參照,您必須對 API 有深入瞭解,或是經常查詢 proto 參照說明文件,找出確切路徑。
ProtoLookupUtil
有了 Proto 查詢公用程式,您就能查詢及建立服務、作業、列舉和資源的執行個體,不必追蹤 API 版本號碼和命名空間。
以下是廣告活動的典型例項化方式:
campaign = Google::Ads::GoogleAds::V21::Resources::Campaign.new
不過,使用 proto 查閱公用程式時,您可以採用較簡單的形式:
campaign = client.resource.campaign
擷取資源、服務或作業時,系統會傳回該實體的執行個體。擷取列舉時,系統會傳回類別的參照,但不會例項化。
對於列舉,您可以使用快速鍵,略過查閱列舉原型。
campaign.status = :PAUSED
即使您沒有其他用途,我們仍建議使用 client.service
方法擷取服務。這個方法內建額外的邏輯,可傳遞開發人員權杖和驗證詳細資料,如果您使用其他方法,就必須手動處理這些資料。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-09-05 (世界標準時間)。
[null,null,["上次更新時間:2025-09-05 (世界標準時間)。"],[[["\u003cp\u003eThe ProtoLookupUtil simplifies interactions with the Google Ads API by removing the need to specify API version numbers and namespaces when working with services, operations, enumerations, and resources.\u003c/p\u003e\n"],["\u003cp\u003eInstead of manually instantiating proto classes with complex paths, the utility allows you to create and access them using a more concise and intuitive syntax, such as \u003ccode\u003eclient.resource.campaign\u003c/code\u003e instead of \u003ccode\u003eGoogle::Ads::GoogleAds::V18::Resources::Campaign.new\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eIt offers a shortcut for using enumerations directly, like assigning \u003ccode\u003e:PAUSED\u003c/code\u003e to a campaign status, without requiring explicit proto lookups.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003eclient.service\u003c/code\u003e is recommended for fetching services, as it automatically handles developer token and authentication details.\u003c/p\u003e\n"]]],[],null,["# Lookup Util\n\nFetching references to proto classes when using the API requires that you either\nhave an intrinsic understanding of the API or need to frequently look up the\nproto reference documentation for the exact path.\n\nProtoLookupUtil\n---------------\n\nThe proto lookup util lets you look up and create instances of services,\noperations, enumerations, and resources without having to keep track of API\nversion numbers and namespaces.\n\nHere's how you typically instantiate a campaign: \n\n campaign = Google::Ads::GoogleAds::V21::Resources::Campaign.new\n\nBut with the proto lookup util, you can use a simpler form: \n\n campaign = client.resource.campaign\n\nWhen fetching a resource, service, or operation, an instance of that entity is\nreturned. When fetching an enumeration, a reference to the class is returned,\nwithout instantiation.\n\nFor enumerations, you can use a shortcut to bypass the need for looking up the\nenumeration protos. \n\n campaign.status = :PAUSED\n\nWe recommend using the `client.service` method to fetch services even if you\ndon't use this utility for any other use cases. There is extra logic built into\nthis method to pass along your developer token and authentication details, which\nyou would have to handle manually if you used another method."]]