google 广告 API 身份验证失败 - "PERMISSION_DENIED"

google ads API authentication failed - "PERMISSION_DENIED"

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

任何人都可以解释一下吗?

谢谢

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

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

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

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

  2. 方法应该是POST

  3. 检查body部分的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. 设置Headers 密钥:授权值:您在上面生成的不记名访问令牌 键:developer-token 值:您的开发人员令牌 键:login-customer-id 值:不带连字符的经理帐户客户 ID

收到 200 条客户详细信息响应后,开始开发代码。

我担任客户经理角色,但遇到了同样的错误。 我通过在创建客户端

时简单地指定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': '-----'}