广告词API正在获取customerId



我有一个adwords用户的Oauth凭据,我可以成功地调用API下载报告,但我不得不在customerId中硬编码,因为我不知道如何获取它。

API中CustomerService的get()方法应该返回客户ID,但是要传递给它的参数是什么?

我尝试了对此URL的GET请求没有任何标头参数或正文参数,返回到:

 "<html><body>No service was found.</body></html>".

我还尝试了在标题中定义Authorization和developerToken,但得到了相同的响应。

我还尝试了python库,并像这样定义了AdWordsClient的一个实例,但它的client_customer_id变量最终为None:

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)

与此问题不同,我不关心将用户添加到我的MCC帐户。

以下是如何使用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']
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'])

相关内容

  • 没有找到相关文章

最新更新