Google Adwords - CUSTOMER_ID_IS_REQUIRED 错误(Python)

Posted

技术标签:

【中文标题】Google Adwords - CUSTOMER_ID_IS_REQUIRED 错误(Python)【英文标题】:Google Adwords - CUSTOMER_ID_IS_REQUIRED ERROR (Python) 【发布时间】:2018-07-11 16:45:56 【问题描述】:

我正在尝试使用 Google Adwords Test API。我正在尝试连接到 Google Adwords API,但我不断收到以下错误:

googleads.errors.GoogleAdsServerFault: [AuthenticationError.CLIENT_CUSTOMER_ID_IS_REQUIRED @ ; trigger:'<null>']

我创建了一个 Google Adwords 生产帐户以获取开发者 API 密钥。然后,我创建了一个 Google Adwords Manager 测试帐户,并设法获得了 Oauth Client id 和 Secret Id。然后我使用Google Oauth 2.0 playground 来获取刷新令牌。我的 google_adwords.yaml 文件现在看起来像这样:

# AdWordsClient configurations
adwords:
  #############################################################################
  # Required Fields                                                           #
  #############################################################################
  developer_token: **DEVELOPER TOKEN FROM PRODUCTION ACCOUNT PASTED HERE**
  #############################################################################
  # Optional Fields                                                           #
  #############################################################################
  # client_customer_id: **CLIENT CUSTOMER ID FROM MANAGER TEST ACCOUNT PASTED HERE** 
  # user_agent: INSERT_USER_AGENT_HERE
  # partial_failure: True
  # validate_only: True
  #############################################################################
  # OAuth2 Configuration                                                      #
  # Below you may provide credentials for either the installed application or #
  # service account flows. Remove or comment the lines for the flow you're    #
  # not using.                                                                #
  #############################################################################
  # The following values configure the client for the installed application
  # flow.
  client_id: **CLIENT ID FROM MANAGER TEST ACCOUNT PASTED HERE** 
  client_secret: **CLIENT CUSTOMER SECRET FROM MANAGER TEST ACCOUNT PASTED HERE** 
  refresh_token: **REFRESH TOKEN FROM OAUTH PLAYGROUND ON BEHALF OF MANAGER TEST ACCOUNT PASTED HERE** 
  # The following values configure the client for the service account flow.
  # path_to_private_key_file: INSERT_PATH_TO_JSON_KEY_FILE_HERE
  # delegated_account: INSERT_DOMAIN_WIDE_DELEGATION_ACCOUNT
  #############################################################################
  # ReportDownloader Headers                                                  #
  # Below you may specify boolean values for optional headers that will be    #
  # applied to all requests made by the ReportDownloader utility by default.  #
  #############################################################################
  # report_downloader_headers:
    # skip_report_header: False
    # skip_column_header: False
    # skip_report_summary: False
    # use_raw_enum_values: False

我的 Python 代码如下所示:

    from googleads import adwords

adwords_client = adwords.AdWordsClient.LoadFromStorage('C:\Python36\google_adwords.yaml')
ad_group_service = adwords_client.GetService('TargetingIdeaService', version='v201806')

selector = 
    'ideaType': 'KEYWORD',
    'requestType': 'IDEAS'


selector['requestedAttributeTypes'] = [
    'KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES']

offset = 0
selector['paging'] = 
    'startIndex': str(offset),
    'numberResults': str(5)


selector['searchParameters'] = [
    'xsi_type': 'RelatedToQuerySearchParameter',
    'queries': ['dog']
]

page = ad_group_service.get(selector)

print (page)

有人知道我哪里出错了吗?我认为我的 YAML 文件有问题,但不能完全确定它可能是什么。提前致谢。

【问题讨论】:

【参考方案1】:

您需要在配置文件中取消注释 client_customer_id 行并插入您创建的测试帐户的 ID。

该项目被标记为可选,因为有一个单独的服务 CustomerService 不需要它 - 相反,CustomerService 允许您检索经过身份验证的用户的可访问帐户的 ID。

但对于您想要访问的所有其他服务,包括TargetingIdeaService,这是必需的设置。

【讨论】:

以上是关于Google Adwords - CUSTOMER_ID_IS_REQUIRED 错误(Python)的主要内容,如果未能解决你的问题,请参考以下文章

google adwords api 与 google-adwords-api gem

与链接到 Google Adwords 帐户的 Google Analytics API 相比,Google Adwords API 报告可以获得多少?

通过 Google Adwords API 获取可用于特定 Adwords 报告的字段列表

Google Adwords API 响应解析

google adwords 中的自动标记

如何恢复?暂停 google Adwords 帐户