查找 Util
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
使用 API 时,如果需要获取对 proto 类的引用,您要么需要对 API 有深入的了解,要么需要经常查找 proto 参考文档以获取确切的路径。
ProtoLookupUtil
借助 proto 查找实用程序,您可以查找和创建服务、操作、枚举和资源实例,而无需跟踪 API 版本号和命名空间。
以下是实例化广告系列的典型方式:
campaign = Google::Ads::GoogleAds::V21::Resources::Campaign.new
不过,借助 proto 查找实用程序,您可以使用更简单的形式:
campaign = client.resource.campaign
在提取资源、服务或操作时,系统会返回相应实体的实例。在提取枚举时,系统会返回对该类的引用,而不会进行实例化。
对于枚举,您可以使用快捷方式来避免查找枚举 proto。
campaign.status = :PAUSED
我们建议您使用 client.service
方法来提取服务,即使您不将此实用程序用于任何其他使用情形也是如此。此方法内置了额外的逻辑来传递您的开发者令牌和身份验证详细信息,如果您使用其他方法,则必须手动处理这些信息。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-27。
[null,null,["最后更新时间 (UTC):2025-08-27。"],[[["\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."]]