gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:42:07 25 4
gpt4 key购买 nike

有两种类型的 Google Ads 帐户。直接账户和经理账户。

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

这是我到目前为止尝试过的:

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

 URL: 'https://googleads.googleapis.com/v1/customers:listAccessibleCustomers?key=XXXXXX',

我正在获取链接到 Gmail 帐户的广告帐户。我有 4 个广告帐户。

1,2,3 是普通的广告帐户。 4 是经理帐户,有 2 个广告帐户与之关联。

我可以使用下面的查询访问下面的 URL 来获取它们:

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_client_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])

关于google-api - 如何从 Google Ads API 获取所有帐户的树?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57491096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com