我有adwords用户的Oauth凭据,并且我能够成功进行API调用以下载报告,但我不得不在customerId中进行硬编码,因为我无法弄清楚如何获得它。
API中CustomerService的get()方法应返回客户ID,但传递给它的参数是什么?
我向this URL尝试了GET请求 没有任何标题参数或身体参数,它返回:
"<html><body>No service was found.</body></html>".
我也试过在头文件中定义了Authorization和developerToken,但得到了相同的响应。
我还尝试了python library,并定义了这样的AdWordsClient实例,但它的client_customer_id变量最终为无:
from googleads.adwords import AdWordsClient
oauth_client = GoogleRefreshTokenClient(environ.get('GOOGLE_CLIENT_ID'), environ.get('GOOGLE_CLIENT_SECRET'), oauth_record.refresh_token)
adwords_client = AdWordsClient(environ.get('ADWORDS_DEVELOPER_TOKEN'), oauth_client, user_agent='agent'))
customer_id = adwords_client.client_customer_id
print 'customer_id:' + str(customer_id)
与this question不同,我并不关心将用户添加到我的MCC帐户。
答案 0 :(得分:3)
以下是如何使用googleads-python-lib库获取客户ID:
oauth_client = GoogleRefreshTokenClient(environ.get('GOOGLE_CLIENT_ID'), environ.get('GOOGLE_CLIENT_SECRET'), oauth_record.refresh_token)
adwords_client = AdWordsClient(environ.get('ADWORDS_DEVELOPER_TOKEN'), oauth_client, user_agent='your_user_agent_here')
customer = adwords_client.GetService('CustomerService').get()
customer_id = customer['customerId']
答案 1 :(得分:0)
from googleads import oauth2, adwords
oauth_client = oauth2.GoogleRefreshTokenClient(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET, refresh_token)
adwords_client = adwords.AdWordsClient(ADWORDS_DEVELOPER_TOKEN, oauth_client, user_agent='your_user_agent')
customers = adwords_client.GetService('CustomerService', version='v201809').getCustomers()
print(customers['customer_id'])