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')
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups
"Google Ads API and AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/adwords-api/ef68d48c-b24c-4925-8000-83b128584264n%40googlegroups.com.