【问题标题】:Adwords API - AuthorizationError.USER_PERMISSION_DENIED - PythonAdwords API - AuthorizationError.USER_PERMISSION_DENIED - Python
【发布时间】:2018-07-17 13:42:12
【问题描述】:

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

googleads.errors.GoogleAdsServerFault: [InternalApiError.UNEXPECTED_INTERNAL_API_ERROR @ com.google.ads.api.services.common.error.InternalApiError.<init>(InternalApiErro]

我创建了一个 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 代码如下所示:

# -*- coding: utf-8 -*-
from googleads import adwords

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

selector = {
    'ideaType': 'KEYWORD',
    'requestType': 'IDEAS'
}
page = ad_group_service.get(selector)

print (page)

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

【问题讨论】:

    标签: python google-ads-api


    【解决方案1】:

    我发现了我的问题。我的 client_customer_id 错误。我使用的是我的测试经理帐户中的 id,但这是不正确的。您需要在您的测试经理帐户中创建一个新的测试客户 adwords 帐户:

    单击该按钮后,我可以通过“邀请用户加入此帐户”部分将测试客户端链接到我的 MCC 帐户(具有我的测试开发者令牌的帐户):

    现在我已关联我的测试帐户和我的 MCC 帐户。

    然后,我将我的测试客户 adwords 帐户 ID (xxx-xxx-xxxx) 粘贴到我的 YAML 文件的“client_customer_id”部分。我运行我的脚本,发现我已经成功连接到 API!

    【讨论】:

    • 您知道如何以编程方式获取它吗?就像有人给你他们的凭据一样,我可以使用他们的三个凭据来提取 client_customer_id 以便我可以执行代码示例吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-12
    • 2014-05-23
    • 1970-01-01
    相关资源
    最近更新 更多