【发布时间】: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