PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `401 Unauthorized` response

1,915 views
Skip to first unread message

Brijesh Kumar

unread,
May 16, 2019, 6:38:08 AM5/16/19
to AdWords API and Google Ads API Forum

Hi,
When executing php examples/BasicOperations/GetCampaigns.php
getting an error
PHP Fatal error: Uncaught GuzzleHttp\Exception\ClientException: Client error: POST https://oauth2.googleapis.com/token resulted in a 401 Unauthorized response:
{
"error": "unauthorized_client",
"error_description": "Unauthorized"
}
in /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::Guz in /home/buzzyears/Downloads/google-ads-php/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 11

Please suggest the correct solution

Thanks
Brijesh

googleadsapi...@google.com

unread,
May 16, 2019, 1:40:25 PM5/16/19
to AdWords API and Google Ads API Forum
Hello Brijesh, 

The error usually occurs when you're using the incorrect set of OAuth credentials. Could you check if you have provided the correct client credentials (client Id, client secret) and the OAuth token? If you are not sure, you could try generating a new refresh token by following the instructions provided here

To validate the credentials that you're using, you could also try the CURL request provided below and see if you are able to generate the access tokens. If the credentials are correct, you should get an access token for the below request.
curl https://www.googleapis.com/oauth2/v4/token \
-d refresh_token=MCC_refresh_token \
-d client_id=your-client-id \
-d client_secret=your-client-secret \
-d grant_type=refresh_token

Please give this a try and let me know how it goes. 

Regards,
Bharani, Google Ads API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    https://ads-developers.googleblog.com/search/label/google_ads_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

Reply all
Reply to author
Forward
0 new messages