admob ListPublisherAccounts fails

33 views
Skip to first unread message

Patricio Tojo

unread,
Apr 23, 2024, 3:37:40 PMApr 23
to AdMob API Developer Forum
Hi! I am having the following issue when trying to download admob's report using its API.
First I need to retrieve the publisher_id for some business reason, and I am using the following method:
- service.accounts().list(pageSize=1).execute()["account"]

where service is created as shown below:
from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials
credentials = Credentials(**creds_dict)
        service = build(
            "admob", "v1", credentials=credentials, cache_discovery=False, num_retries=5
        )

 The process runs ok 90% of the times, but sometimes it fails with the following error.

google_auth_httplib2.request: Refreshing credentials due to a 401 response. Attempt 1/2. [WARNING] | googleapiclient.http._should_retry_response: Encountered 403 Forbidden with reason "PERMISSION_DENIED"
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://admob.googleapis.com/v1/accounts?pageSize=1&alt=json returned "Request had insufficient authentication scopes.". Details: "[{'@ type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'ACCESS_TOKEN_SCOPE_INSUFFICIENT', 'domain': 'googleapis.com', 'metadata': {'service': 'admob.googleapis.com', 'method': 'google.ads.admob.v1.AdMobApi.ListPublisherAccounts'}}]">

In some cases it might works after 15 retries more or less, but I cant figure out the main reason of this behaviour.

Any idea? Thanks in advance!


Lin Yang

unread,
Apr 23, 2024, 3:43:23 PMApr 23
to AdMob API Developer Forum
Since the auth error is intermittent and the error message mentioned refreshing credentials, it might be due to OAuth refresh token setup issues. Please take a look at the official OAuth documentation related to refresh tokens. There are also AdMob API specific code samples on Github that demonstrates how to configure refresh tokens. Hope those help.
Reply all
Reply to author
Forward
0 new messages