Error while running GetCampaigns.php file

466 views
Skip to first unread message

sz...@mymail.mines.edu

unread,
Jun 6, 2018, 6:04:27 AM6/6/18
to AdWords API and Google Ads API Forum

Hi there, I've been following along with the Adwords API Dev series on youtube to help me setup my API, however, when running the getCampaigns.php file through terminal, I run into the following error:

Fatal error: Uncaught exception 'GuzzleHttp\Exception\ClientException' with message 'Client error: POST https://www.googleapis.com/oauth2/v4/token resulted in a 401 Unauthorized response:
{
"error": "unauthorized_client",
"error_description": "Unauthorized"
}

' in /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/guzzle/src/Middleware.php(66): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response))
#1 /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/promises/src/Promise.php(203): GuzzleHttp\Middleware::GuzzleHttp{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/promises/src/Promise.php(156): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), Array)
#3 /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/promises/src/TaskQueue.php(47): GuzzleHttp\Promise\Promise::Guzzle in /Users/SeanZusi/googleads-php-lib/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113


Not sure what the issue is, please let me know what the best way to go about fixing this is.

Dhanya Sundararaju (AdWords API Team)

unread,
Jun 6, 2018, 10:43:16 AM6/6/18
to AdWords API and Google Ads API Forum
Hi Szusi,

To verify that your credentials are correct, you can 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=your-refresh_token \
-d client_id=your-client-id \
-d client_secret=your-client-secret \
-d grant_type=refresh_token

If your credentials are incorrect and still facing issues then please follow below steps:
  1. Open a new incognito window. 
  2. Generate the client id and secret using a valid AdWords user login. 
  3. Generate the refresh token using the GetRefreshToken.php
  4. Use those credentials to run GetCampaigns.php
Let me know if you still get errors.

Regards,
Dhanya, AdWords API Team

sz...@mymail.mines.edu

unread,
Jun 6, 2018, 11:19:54 AM6/6/18
to AdWords API and Google Ads API Forum
Thanks for the suggestion, unfortunately, after running the curl request I receive:  

 "error": "invalid_client",

 "error_description": "The OAuth client was not found."

Which is odd because I was able to use GenerateRefreshToken.php using the same credentials. What is the next step?

Dhanya Sundararaju (AdWords API Team)

unread,
Jun 6, 2018, 4:39:20 PM6/6/18
to AdWords API and Google Ads API Forum
Hi Szusi,

Could you confirm that the clientId field in your adsapi_php.ini is the same as the one in your project within Google API Console Credentials page? Please refer this guide for better clarity and let me know if you have further questions.

virender.s...@gmail.com

unread,
Feb 19, 2019, 10:35:42 AM2/19/19
to adwor...@googlegroups.com
Hi Dhanya,

I am also getting the same error 401 Unauthorized response. I have verified credentials using CURL and it is working fine. I am getting response "{ "access_token": "XXXX", "expires_in": 3600, "scope": "https://www.googleapis.com/auth/adwords", "token_type": "Bearer" }".

Please help me!

Regards,
Virender

googleadsapi...@google.com

unread,
Feb 19, 2019, 2:21:39 PM2/19/19
to AdWords API and Google Ads API Forum
Hi Virender,

I have masked the sensitive information from your post. Moving further, regarding your issue, could you check the emailid for which the OAuth was created is the same emailid that you are making API calls with and also has access to the Google Ads account? If not, please reply back with your Client customer id and emaild, so that I can check further. You may reply privately to author.


Regards,
Dhanya, AdWords API Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_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