Google api 如何从Google Ads API获取所有帐户的树?

Google api 如何从Google Ads API获取所有帐户的树?,google-api,google-ads-api,Google Api,Google Ads Api,有两种类型的谷歌广告帐户。直接客户和经理客户 我需要列出所有的广告帐户。必须排除经理帐户,但必须填充在其下链接的帐户 以下是我迄今为止所做的尝试: 首先,我向以下URL发出GET请求: URL: 'https://googleads.googleapis.com/v1/customers:listAccessibleCustomers?key=XXXXXX', https://googleads.googleapis.com/v2/customers/'+selectedCustomerID

有两种类型的谷歌广告帐户。直接客户和经理客户

我需要列出所有的广告帐户。必须排除经理帐户,但必须填充在其下链接的帐户

以下是我迄今为止所做的尝试:

首先,我向以下URL发出GET请求:

 URL: 'https://googleads.googleapis.com/v1/customers:listAccessibleCustomers?key=XXXXXX',
https://googleads.googleapis.com/v2/customers/'+selectedCustomerID+'/googleAds:search


SELECT customer.id,  customer.resource_name, customer.descriptive_name, customer.manager, customer.test_account FROM  customer_client where customer.id ="+ selectedCustomerID
我正在获取链接到Gmail帐户的广告帐户。我有4个广告账户

1、2、3为正常Ad账户。4是一个经理帐户,其中有两个Ad帐户与其链接

我可以通过点击以下URL的以下查询获取它们:

 URL: 'https://googleads.googleapis.com/v1/customers:listAccessibleCustomers?key=XXXXXX',
https://googleads.googleapis.com/v2/customers/'+selectedCustomerID+'/googleAds:search


SELECT customer.id,  customer.resource_name, customer.descriptive_name, customer.manager, customer.test_account FROM  customer_client where customer.id ="+ selectedCustomerID
这将返回类似以下内容的数据:

对于帐户1和3,我得到以下错误:

The caller does not have permission
对于帐户2,我正在获取数据

对于第4个帐户,我得到了它下面链接的所有帐户以及经理帐户的
manager:true
,我在它下面收到了5个帐户

理想情况下,我应该收到3个
manager:false
账户和1个
manager:true
账户,以及其中的2个子账户


在这种情况下,我的方法应该是什么?

我使用customer\u client\u link服务实现了这一点。请记住,下面的代码切掉了资源名称,只返回CID的层次结构

def get_hierarchy(client, customer_id):
ga_service = client.get_service('GoogleAdsService', version='v3')

query = "SELECT customer_client_link.client_customer FROM customer_client_link"

# Issues a search request using streaming.
response = ga_service.search_stream(customer_id, query)

try:
    for batch in response:
        for row in batch.results:
            # row.customer_client_link.client_customer contains additional trailing and leading text, but is
            # non-subscriptable so we need to cast it directly then slice the result.
            customer = str(row.customer_client_link.client_customer)
            # Remove the sliding to get the full resource name.
            print(customer[18:-2])

ListAccessibleCustomers
返回一些Google帐户可以直接访问的客户的资源名称。您可以从响应中筛选经理帐户,并列出经理帐户的所有客户端帐户。客户帐户可以按以下方式访问。因为客户也可能是经理,所以您可能需要某种递归来构建accounts树。关键是什么?