How to find functions/methods under certain resource?

26 views
Skip to first unread message

Yang Wenjun

unread,
Jul 22, 2019, 3:52:53 AM7/22/19
to AdWords API and Google Ads API Forum
Hi Team,

I found I lost in the document you provided for new Google Ads API.  
For example, I know how to get customer detail information, but I know it from your example code as below. 

def main(client, customer_id):
customer_service = client.get_service('CustomerService', version='v2')

resource_name = customer_service.customer_path(customer_id)

try:
customer = customer_service.get_customer(resource_name=resource_name)
except google.ads.google_ads.errors.GoogleAdsException as ex:
pass


My Questions is :
where I can find there is a method called 'customer_path' and 'get_customer' under service 'CustomerService' ?

The only way I found right now is dive deep into the python source code.


Wenjun Yang

Google Ads API Forum Advisor Prod

unread,
Jul 22, 2019, 3:45:19 PM7/22/19
to yang.ra...@gmail.com, adwor...@googlegroups.com
Hi Yang,

Thank you for the question! I see you're using Python so I'll give you my advice from a Python perspective.

Currently there is not good documentation for the methods on each of the services in Python. From a general standpoint you can review these docs, which describe each of the services and methods defined in the source Protobuf definitions, but they do not provide much detail about how each method is implemented in Python. 

Right now the best source of information is to look at the services source code in the Python library, for example here are all the services for v2. All of the services are well documented and will tell you what each of the parameters are. You can also find methods that aren't defined at the protobuf level, such as the helper methods that construct resource names. 

On a separate note, regarding resource names, you can check the format for resource names for all objects in the API by looking at the Google Ads Developer Site, for example here's the definition for AdGroupAd. Some resource names, including those for AdGroupAds, contain a compound ID, which is the section at the end separated by a '~'. The resource name methods in Python require that those sections be constructed before being passed into the method, which can be confusing. So we have a utility that helps construct those compound IDs, you can see how it's used here.

One last bit of advice, which is something I use quite a lot, is to print the list of a service's attributes using dir to see what methods it has, then use the __doc__ attribute to see it's documentation. It would give you info about the parameters, but it's a useful starting point before digging through the source code.

I'll add a suggestion for us to add language-specific documentation for the service methods and hopefully we can improve this in the future.

Thanks,
Ben Karl, Google Ads API Team


ref:_00D1U1174p._5001UEFyDn:ref

Yang Wenjun

unread,
Jul 22, 2019, 11:10:02 PM7/22/19
to AdWords API and Google Ads API Forum
Hi Team,

Thanks a lot for your tips, they did helps!

Thanks again.

Wenjun

在 2019年7月23日星期二 UTC+8上午3:45:19,adsapiforumadvisor写道:

Google Ads API Forum Advisor Prod

unread,
Jul 23, 2019, 9:17:28 AM7/23/19
to yang.ra...@gmail.com, adwor...@googlegroups.com
You're very welcome!

Best,
Ben, Google Ads API Team

ref:_00D1U1174p._5001UEFyDn:ref
Reply all
Reply to author
Forward
0 new messages