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

Tag:google-ads-api, google-oauth

8 comments.

  1. fatima Ajij

    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

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

    Method should be POST

    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.

    Set URL to https://googleads.googleapis.com/v6/customers/your client customer id without hyphen. Method Get 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.

    1. md samual

      Can I use postman for testing all Google ads api endpoint? If so please provide postman collection link.

    2. fatima Ajij

      @mdsamual Here is the link where you would be able to find Rest methods developers.google.com/google-ads/api/docs/rest/common/overview

    3. fatima Ajij

      googleads.googleapis.com/v6/customers/customerid-without-hyphen/… (Please note that this link would provide you to customize number of results per request by using pageSize parameter)

    4. fatima Ajij

      googleads.googleapis.com/v6/customers/3072947393/… (This link would bring all results in one request)

  2. Dave Davis

    Do you have admin access to the manager account?

    1. inbal_bpr

      No, I have "standard", and I've been told it should be sufficient. Do I have to have an admin access?

  3. Максим Ефремов

    I had the account manager role and was catching the same error. I solved the problem by simply specifying the API version when creating the client

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

    After that, I was able to get data on accounts Creeds like that

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

Add a new comment.