I need to fetch all the accounts a user has access to. I'm using the python 
library.
At the moment I do something like this, but it seems an overkill and 
multiple loops / calls.



 oauth2_client = oauth2.GoogleRefreshTokenClient(app.config[
'GOOGLE_CLIENT_ID'], app.config['GOOGLE_CLIENT_SECRET'], creds[
'refresh_token'])
 adwords_client = adwords.AdWordsClient(app.config['ADWORDS_DEV_TOKEN'], 
oauth2_client)


 campaign_service = adwords_client.GetService('CampaignService', version=
'v201710')
 customers = adwords_client.GetService('CustomerService').getCustomers()


 for top_customer in customers: # Top Adwords accounts
 client_customer_id = str(top_customer.customerId)


 top_adwords_client = adwords.AdWordsClient(app.config['ADWORDS_DEV_TOKEN'], 
oauth2_client, 'user_agent', client_customer_id=client_customer_id)
 # Get managed accounts
 accounts = top_adwords_client.GetService('ManagedCustomerService').get({ 
'fields': ['CustomerId', 'CanManageClients'] })


 if 'entries' in accounts:
 for account in accounts['entries']:
 account_id = account.customerId
 adwords_client = adwords.AdWordsClient(app.config['ADWORDS_DEV_TOKEN'], 
oauth2_client, 'user_agent', client_customer_id=account_id)
 campaign_service = adwords_client.GetService('CampaignService', version=
'v201710')


Is there a way to simplify this code and just get directly all the ads a 
user has access to?

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/d9a68708-3c12-49a3-a94c-58d09d2f1a66%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to