首页 文章

Adwords API - AuthorizationError.USER_PERMISSION_DENIED - Python

提问于
浏览
0

我正在尝试使用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 Manager测试帐户,并设法获得了一个Oauth客户端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文件有问题,但不能完全放置它的位置 . 提前致谢!

1 回答

  • 0

    我想出了我的问题 . 我的client_customer_id错了 . 我正在使用我的测试经理帐户中的ID,但这是不正确的 . 您需要在测试经理帐户中设置新的测试客户端adwords帐户:

    enter image description here

    点击该按钮后,我可以将测试客户端链接到我的MCC帐户(包含我的测试开发人员令牌的帐户)和“邀请用户加入此帐户”部分:

    enter image description here

    现在我已将我的测试帐户与我的MCC帐户相关联 .

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

相关问题