"User in the cookie is not a valid Ads user."

69 views
Skip to first unread message

Enzo Pucci

unread,
May 4, 2023, 8:54:37 PM5/4/23
to Google Ads API and AdWords API Forum
Hi,

I am trying to run a sample code in Python to use google query language but I'm getting the error as above. However, I've already managed to do a script that returns all of my campaigns.

The current script that I'm trying to run is this:

import google.auth
from google.auth.transport.requests import Request
from google.oauth2 import service_account
from google.ads.googleads.client import GoogleAdsClient

# Configuração
DEVELOPER_TOKEN = "xxxxxxx-xxxxxxxxxxxxx"
PATH_TO_CREDENTIALS = "caminhoParaCredenciais.json"
CUSTOMER_ID = "xxxxxxxxxx" (I've already tried with a -)

def get_google_ads_data(credentials_path, developer_token, customer_id):
    try:
        # Autenticação
        credentials = service_account.Credentials.from_service_account_file(credentials_path)
        credentiaels = credentials.with_scopes(['https://www.googleapis.com/auth/adwords'])

        # Criar cliente do Google Ads
        google_ads_client = GoogleAdsClient(credentials=credentials, developer_token=developer_token)

        # Construir a consulta
        query = f"""
            SELECT
                campaign.id
                # ad_group.id,
                # ad.id,
                # ad.type,
                # ad.headline,
                # ad.description,
                # metrics.impressions,
                # metrics.clicks,
                # metrics.average_cpc
            FROM
                ad
            WHERE
                segments.date DURING LAST_7_DAYS
                AND metrics.impressions > 0
        """

        ga_service = google_ads_client.get_service("GoogleAdsService")
       
        # Executar a consulta
        response = ga_service.search_stream(customer_id=customer_id, query=query)

        # Exibir resultados
        for batch in response:
            for row in batch.results:
                print(f"Ad ID: {row.ad.id.value}, Headline: {row.ad.headline.value}, Impressions: {row.metrics.impressions.value}")

    except Exception as e:
        print(f"An error occurred: {e}")
        return None

if __name__ == "__main__":
    get_google_ads_data(PATH_TO_CREDENTIALS, DEVELOPER_TOKEN, CUSTOMER_ID)

But I'm getting this return:
Request made: ClientCustomerId: xxxxxxxxx, Host: googleads.googleapis.com, Method: /google.ads.googleads.v13.services.GoogleAdsService/SearchStream, RequestId: rAdWhFeZYtpdmODskp5SVQ, IsFault: True, FaultMessage: User in the cookie is not a valid Ads user.
An error occurred: (<_SingleThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "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."
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.219.10:443 {grpc_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.", grpc_status:16, created_time:"2023-05-03T17:28:14.912279934+00:00"}"
>, <_SingleThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAUTHENTICATED
details = "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."
debug_error_string = "UNKNOWN:Error received from peer ipv4:142.250.219.10:443 {grpc_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.", grpc_status:16, created_time:"2023-05-03T17:28:14.912279934+00:00"}"
>, errors {
  error_code {
    authentication_error: NOT_ADS_USER
  }
  message: "User in the cookie is not a valid Ads user."
}
request_id: "rAdWhFeZYtpdmODskp5SVQ"
, 'rAdWhFeZYtpdmODskp5SVQ')

Google Ads API Forum Advisor

unread,
May 5, 2023, 8:46:33 AM5/5/23
to enzo.bri...@gmail.com, adwor...@googlegroups.com
Hi,

Thank you for raising this concern to the Google Ads API support team.

Moving forward, I can see that you have received the NOT_ADS_USER (https://developers.google.com/google-ads/api/docs/best-practices/common-errors#authenticationerror) error when you attempted to connect to the API. The NOT_ADS_USER error is encountered when the service account has not been correctly linked to the Google Ads account via the OAuth2 assertion flow. Please take note that the email address you may have used to generate the credentials should have access or be associated with Google Ads accounts. To handle this error, make sure to sign in with a valid Google Ads account (typically your manager account) for the OAuth flow. You can also invite the Google account to access an existing Google Ads account by signing in to your manager account, selecting the customer or manager account in question, navigating to Tools and Settings > Access and security, then adding the Google account email address.

If the issue persists, could you please provide the complete logs below for further investigation:
You may then send the requested logs via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Regards,
Google Logo Google Ads API Team


ref:_00D1U1174p._5004Q2lAV8K:ref
Reply all
Reply to author
Forward
0 new messages