def get_managed_accounts(account_id):
oauth2_client = oauth2.GoogleRefreshTokenClient(
g.credentials['client_id'], g.credentials['client_secret'], g.credentials['refresh_token'])
adwords_client = adwords.AdWordsClient(
os.environ['GOOGLE_ADS_DEVELOPER_TOKEN'],
oauth2_client,
os.environ['GOOGLE_ADS_USER_AGENT'])
managed_customer_service = adwords_client.GetService(MANAGED_CUSTOMER_SERVICE, version=API_VERSION)
offset = 0
selector = {
'fields': ['CustomerId', 'Name','CanManageClients'],
'paging': {
'startIndex': str(offset),
'numberResults': str(PAGE_SIZE)
},
'predicates':[{
'field': 'ExcludeHiddenAccounts',
'operator': 'EQUALS',
'values': ['true']
}]
}
response = {
'accounts':[]
}
more_pages = True
while more_pages:
# THE ERROR OCCURS WHEN THE FOLLOWING LINE IS EXECUTED
page = managed_customer_service.get(selector)
if 'entries' in page:
accounts = page['entries']
for account in accounts:
print(account)
if account['customerId'] == int(account_id):
continue
else:
response['accounts'].append({
'id': account['customerId'],
'name': account['name'],
'canManageClients': account['canManageClients']
})
offset += PAGE_SIZE
selector['paging']['startIndex'] = str(offset)
more_pages = offset < int(page['totalNumEntries'])
return jsonify(**response)