The Oauth Error Of AdMob API - Downloading Reports

191 views
Skip to first unread message

Ryo Hamada

unread,
Oct 3, 2022, 11:49:15 PM10/3/22
to AdMob API Developer Forum
Hi,

I've been trying to get an AbMob report using AdMob API, but I get the error when I request for a report.

I'm following this guidance.

I've attached the python file I wrote.

Here is the command I executed and the error I got.

1. python3 oauthtry.py --mode oauth
-> save credential to admob.dat

2. python3 oauthtry.py --mode download
-> got the error below

> googleapiclient.errors.HttpError: <HttpError 401 when requesting https://admob.googleapis.com/v1/accounts/pub-xxxxxxxxx?alt=json returned "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.">


I have no idea why this error occurs even though I'm just following the guidance.

Could someone please help me solve this and download a report using the API?

Thank you.

oauthtry.py

AdMob API Forum Support

unread,
Oct 11, 2022, 2:56:19 PM10/11/22
to ryo-h...@united.jp, google-admob-api...@googlegroups.com
Hi, thank you for your question.

The error message that you're getting back suggest that there was something wrong with the OAuth token. 

One way to narrow down whether the issue is in the Python code or in the OAuth retrieval process is to try the curl command line process of calling AdMob APIs -- https://developers.google.com/admob/api/v1/getting-started#curl-command-line.

If you follow the above process and you see the same error, then it suggest the problem lies in OAuth setup. If it works for curl command line, then at least you know the problem is the code itself and not in OAuth setup.

Hope this helps.

ref:_00D1U1174p._5004Q2ewwUY:ref

Ryo Hamada

unread,
Oct 12, 2022, 2:38:37 AM10/12/22
to AdMob API Developer Forum
Thank you for your reply.

I have tried the curl command line process like below, and still got the error.

1. oauth2l header --json client_secret_xxxxxx-xxxxxxx.apps.googleusercontent.com.json https://www.googleapis.com/auth/admob.readonly
        -> Authorization: Bearer ya29.xxxxxxxx

2. curl -X GET https://admob.googleapis.com/v1/accounts/pub-xxxxxxxxx -H "$(oauth2l header --json client_secret_xxxxxx-xxxxxxx.apps.googleusercontent.com.json https://www.googleapis.com/auth/admob.readonly)"
        -> here I got the error below.


Could you tell us what the possible causes of this error regarding oauth are?
We have made sure that the publisher id is right, and that we made the oauth 2.0 client in Google API console.

Thank you for your cooperation.



2022年10月12日水曜日 3:56:19 UTC+9 admobapi:

AdMob API Forum Support

unread,
Oct 12, 2022, 4:45:44 PM10/12/22
to ryo-h...@united.jp, google-admob-api...@googlegroups.com
Hello,

To complete authorization, please follow all of the steps on the AdMob API Auth guide. As well, please ensure that you are signed into the correct account when accepting the consent screen and use the refresh token to regenerate the access token which expires intermittently.

All the best,
Google Logo
Amira
AdMob API Team
 


ref:_00D1U1174p._5004Q2ewwUY:ref

Ryo Hamada

unread,
Oct 13, 2022, 6:00:36 AM10/13/22
to AdMob API Developer Forum
Hello,

I have already followed all the steps of the AdMob API Auth guide, and made sure that I use the correct account and the refresh token, but still can not resolve the error I mentioned previously.

I am not sure what causes this error.

Regards,

2022年10月13日木曜日 5:45:44 UTC+9 admobapi:

AdMob API Forum Support

unread,
Oct 14, 2022, 5:06:49 PM10/14/22
to ryo-h...@united.jp, google-admob-api...@googlegroups.com
Hello,

I would recommend to test access by creating a new credential and completing authorization by following all of the steps on the AdMob API getting started guide to validate the setup.
Reply all
Reply to author
Forward
0 new messages