google ads API身份验证失败-"PERMISSION_DENIED" [英] google ads API authentication failed - "PERMISSION_DENIED"

查看:202
本文介绍了google ads API身份验证失败-"PERMISSION_DENIED"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与此处描述的相同:现在,使用端点创建另一个请求,并在此请求中使用生成的访问令牌.

在此示例中,我使用端点来获取客户.

  1. 将URL设置为 https://googleads.googleapis.com/v6/customers/您的不带连字符的客户客户ID.
  2. 方法获取
  3. 设置标题密钥:授权值:您在上方生成的承载访问令牌密钥:开发人员令牌价值:您的开发人员令牌密钥:login-customer-id值:不带连字符的经理帐户客户ID

一旦收到200条有关客户详细信息的回复,就开始开发代码.

My question is the same as described here: How to set request header in google ads api but I'm still facing the problem.
I'm trying to make an API call to google ads. I tried Rest API as well as google.ads.google_ads library. Both ways fail. I followed all Oath2 steps and got all ids, tokens, secrets, etc. The Rest API call is :

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)

and this is the response:

{
  "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"
  }
}

Why? I provided an access token.

I also tried the "google-ads" code I found in the documentation:
https://developers.google.com/google-ads/api/docs/reporting/example
I generated a googleads.ymal file, with the following content:

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

and this is what I get:

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

and again I don't understand why. My user was the one to generate all login details, and it has access to the manager account, which listed as "login-customer-id".

Can anyone shed some light?

Thanks

解决方案

If you are using RestAPI to integrate Google Ads API, try testing this first using postman to make your you are getting response before developing a code in any language.

Follow the following steps to generate the authentication token in postman

  1. Set the request URL to https://www.googleapis.com/oauth2/v3/token

  2. Method should be POST

  3. check x-www-form-urlencoded in body section and fill the following Key: grant_type Value: refresh_token Key: client_id Value: your client id Key: client_secret Value: your client secret Key: refresh_token Value: your refresh token

You are all setup to generate authentication token. Click send button to send request to receive access token (See the picture below). Now create another request with your endpoint and use the generated access token in this request.

In this example, I am using endpoint to get customers.

  1. Set URL to https://googleads.googleapis.com/v6/customers/your client customer id without hyphen.
  2. Method Get
  3. set Headers Key: Authorization Value: Bearer access token you generated above Key: developer-token Value: your developer token Key: login-customer-id Value: Manager Account customer ID without hyphen

Once you get 200 response with customer details, start developing the code.

这篇关于google ads API身份验证失败-"PERMISSION_DENIED"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆