【问题标题】:google ads API authentication failed - "PERMISSION_DENIED"谷歌广告 API 身份验证失败 - “PERMISSION_DENIED”
【发布时间】:2020-12-03 15:09:35
【问题描述】:

我的问题与此处描述的相同: How to set request header in google ads api 但我仍然面临这个问题。
我正在尝试对谷歌广告进行 API 调用。我尝试了 Rest API 以及 google.ads.google_ads 库。两种方式都失败了。 我遵循了所有 Oath2 步骤并获得了所有 ID、令牌、秘密等。 Rest API 调用是:

refresh_token = MY_REFRESH_TOKEN
customer_id = 7868******
developer_token = MY_DEVELOPER_TOKEN
access_token =  MY_ACCESS_TOKEN
url = 'https://googleads.googleapis.com/v6/customers/{}/campaignBudgets:mutate'.format(customer_id)

headers = {'developer-token':developer_token,"Authorization": "Bearer {}".format(access_token),'login-customer-id':'2693******',"Content-Type": "application/json"}
response = requests.post(url,headers = headers)
print(response.text)

这是回应:

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

为什么?我提供了一个访问令牌。

我还尝试了在文档中找到的“google-ads”代码:
https://developers.google.com/google-ads/api/docs/reporting/example
我生成了一个 googleads.ymal 文件,内容如下:

developer_token: MY_DEVELOPER_TOKEN
user_agent: MY_COMPANY_NAME
client-id: 7868******
login-customer-id: 2693******
client_id: MY_CLIENT_ID
client_secret: MY_CLIENT_SECRET
refresh_token: MY_REFRESH_TOKEN

这就是我得到的:

Error with message "User doesn't have permission to access customer. Note: If you're accessing a client customer, the manager's customer id must be set in the 'login-customer-id' header

我还是不明白为什么。我的用户是生成所有登录详细信息的用户,它可以访问经理帐户,该帐户列为“login-customer-id”。

谁能解释一下?

谢谢

【问题讨论】:

    标签: google-oauth google-ads-api


    【解决方案1】:

    如果您使用 RestAPI 来集成 Google Ads API,请先尝试使用邮递员对此进行测试,以便在开发任何语言的代码之前获得响应。

    按照以下步骤在 postman 中生成身份验证令牌

    1. 将请求 URL 设置为 https://www.googleapis.com/oauth2/v3/token

    2. 方法应该是POST

    3. 在正文部分检查 x-www-form-urlencoded 并填写以下内容 键:grant_type 值:refresh_token 键:client_id 值:您的客户 ID 键:client_secret 值:您的客户端密码 键:refresh_token 值:您的刷新令牌

    您已准备好生成身份验证令牌。单击发送按钮发送请求以接收访问令牌(见下图)。 现在使用您的端点创建另一个请求,并在此请求中使用生成的访问令牌。

    在本例中,我使用端点来获取客户。

    1. 将 URL 设置为 https://googleads.googleapis.com/v6/customers/your 客户端客户 ID,不带连字符。
    2. 方法获取
    3. 设置标题 密钥:授权值:您在上面生成的不记名访问令牌 键:developer-token 值:您的开发者令牌 键:login-customer-id 值:经理帐户客户 ID,不带连字符

    在收到 200 条客户详细信息的回复后,开始开发代码。

    【讨论】:

    【解决方案2】:

    您是否拥有经理帐号的管理员权限?

    【讨论】:

    • 不,我有“标准”,有人告诉我应该足够了。我必须拥有管理员权限吗?
    【解决方案3】:

    我担任客户经理角色,但遇到了同样的错误。 我通过在创建客户端时简单地指定API版本解决了这个问题

    client = GoogleAdsClient.load_from_dict(cred_dict, version="v9")
    

    在那之后,我能够获取有关帐户的数据 像这样的信条

    cred_dict = {
    'developer_token': '---------',
    'refresh_token': '------',
    'client_id': '-------',
    'client_secret': '-----',
    'access_token': '------',
    'use_proto_plus': False,
    'login_customer_id': '-----'}
    

    【讨论】:

      猜你喜欢
      • 2016-01-26
      • 2018-07-02
      • 2021-12-06
      • 2017-11-17
      • 2019-03-17
      • 2022-11-08
      • 2016-11-14
      • 2019-06-16
      • 1970-01-01
      相关资源
      最近更新 更多