Google Ads API: Access with service account

5.6k views Asked by At

I am trying to connect to the google ads api using a service account. For analytics there is a good article named Hello Analytics API: Java quickstart for service accounts which explains how to set this up. For Google ads I can't find any documentation online.

So my two questions are:

  1. Is it possible to access the Google Ads API using a service account?
  2. If so, is there something like a Hello Ads API: Java quickstart for service accounts page with information on how to connect to the api with a service account?

UPDATE 2/10

I succeeded in passing the authentication fase. I do get an error when trying to fetch data from the API.

curl.exe --request POST "https://googleads.googleapis.com/v5/customers/******/googleAds:searchStream"
--header "Content-Type: application/json" 
--header "Authorization: Bearer ******" 
--header "developer-token: ******" 
--data "{'query': 'SELECT * FROM campaign WHERE segments.date DURING YESTERDAY'}"

[{
  "error": {
    "code": 401,
    "message": "Request is missing required authentication credential. 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",
    "details": [
      {
        "@type": "type.googleapis.com/google.ads.googleads.v5.errors.GoogleAdsFailure",
        "errors": [
          {
            "errorCode": {
              "authenticationError": "NOT_ADS_USER"
            },
            "message": "User in the cookie is not a valid Ads user."
          }
        ]
      }
    ]
  }
}
]

The google docs say this error is because the account is not associated with an google ads account (https://developers.google.com/google-ads/api/docs/best-practices/common-errors#not_ads_user). The request are being processed by the api, I know this because the request are counted in the google ads api console as errors.

In the Credentials compatible with this API for the google ads Api my service account is listed. I am a little puzzled by the error. The service-account is associated with the google ads account as far as I could tell.

1

There are 1 answers

3
Donnald Cucharo On

According to a caveat on Google Ads API Service Accounts:

Note: Not all our client libraries currently support service accounts. Service accounts can still be used if you implement the OAuth2 service account flow yourself.


Regarding the 2 questions:
  1. Yes, it is possible to access Ads API using service accounts (only with Python and .NET)
  2. Google Ads API recommends Service Account flow however, it is not yet supported in Java.

UPDATE:

Java is now supported.