作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有两种类型的 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/
我是一名优秀的程序员,十分优秀!