I have a problem with authorizing to AdMob API via service accounts. I'm gettings 401 error with 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.
I need to get AdMob reports from the server in non-UI environment(cron job).
I have tried different ways to authenticate: doing requests completely via client library, doing request via Guzzle client returned from client library, manually signing JWT and getting token, but I always get 401 in response.
I have debugged the loading of the service account file, I know it's load correctly. I have checked via proxy what headers do the script send, and I have authorization header with some Bearer token.
Environment details
- OS: Docker php:5.6-fpm
- PHP version: 5.6
- Package name and version: google/apiclient v2.4.0, google/auth v1.7.1
Code example
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope("https://www.googleapis.com/auth/admob.report");
$httpClient = $client->authorize();
$url = "https://admob.googleapis.com/v1/accounts";
$response = $httpClient->get($url);
I have tried the same code, with different scope and a service account file to authorize Google Drive Api, using the same library, the same OS and it worked like a charm. What's wrong with AdMob?
Thanks!
I have a problem with authorizing to AdMob API via service accounts. I'm gettings 401 error with 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.I need to get AdMob reports from the server in non-UI environment(cron job).
I have tried different ways to authenticate: doing requests completely via client library, doing request via Guzzle client returned from client library, manually signing JWT and getting token, but I always get 401 in response.
I have debugged the loading of the service account file, I know it's load correctly. I have checked via proxy what headers do the script send, and I have
authorizationheader with someBearertoken.Environment details
Code example
I have tried the same code, with different scope and a service account file to authorize Google Drive Api, using the same library, the same OS and it worked like a charm. What's wrong with AdMob?
Thanks!