Google Ads API PHP client reported invalid_grant error

1,324 views
Skip to first unread message

hailong zhou

unread,
May 23, 2021, 11:13:30 PM5/23/21
to AdWords API and Google Ads API Forum
I'm ready to OAuth2 client ID and secret, a developer token, and a refresh token,But when I execute GetCampaigns.php in the example program, I get the following error

PHP Fatal error:  Uncaught GuzzleHttp\Exception\ClientException: Client error: `POST https://oauth2.googleapis.com/token` resulted in a `400 Bad Request` response:
{
  "error": "invalid_grant",
  "error_description": "Bad Request"
}
 in /home/gg/google-ads-php/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
Stack trace:
#0 /home/gg/google-ads-php/vendor/guzzlehttp/guzzle/src/Middleware.php(69): GuzzleHttp\Exception\RequestException::create(Object(GuzzleHttp\Psr7\Request), Object(GuzzleHttp\Psr7\Response), NULL, Array, NULL)
#1 /home/gg/google-ads-php/vendor/guzzlehttp/promises/src/Promise.php(204): GuzzleHttp\Middleware::GuzzleHttp\{closure}(Object(GuzzleHttp\Psr7\Response))
#2 /home/gg/google-ads-php/vendor/guzzlehttp/promises/src/Promise.php(153): GuzzleHttp\Promise\Promise::callHandler(1, Object(GuzzleHttp\Psr7\Response), NULL)
#3 /home/gg/google-ads-php/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\Promise::GuzzleHttp\Promise\{closure}()
#4 /home/gg/google-ads-php/vendor/guzzlehttp/pr in /home/gg/google-ads-php/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113

Google Ads API Forum Advisor Prod

unread,
May 24, 2021, 4:54:13 PM5/24/21
to pipe...@gmail.com, adwor...@googlegroups.com
Hi Hailong,

Thank you for bringing this issue to our attention. In looking voer the docuemnts, I want to just make sure that you have done the following items. As it looks like there has been an erroro in setting up the account which is why you would get this.
  • Have you checked to make sure that you have the correct account Id and secret Word, as shown here ..
  • Have you setup the refresh tokens, as shown here , and all the ids at the top level of the files.
  • You can also check out this previous thread that showed this same issue.
Regards,
Google Logo
William Pescherine
Google Ads API Team
 


ref:_00D1U1174p._5004Q2HD6M1:ref

hailong zhou

unread,
Jun 8, 2021, 3:49:10 AM6/8/21
to AdWords API and Google Ads API Forum
Hi William,

I created another test account and the call was successful, but the production account call fails

The following is my test account call successful content

# php GetCampaigns.php --customerId=3602938739
Campaign with ID 13322273954 and name 'App promotion-App-1' was found.
[2021-06-08T15:12:05.048847+08:00] google-ads.INFO: Request made: Host: "googleads.googleapis.com", Method: "/google.ads.googleads.v6.services.GoogleAdsService/SearchStream", CustomerId: 3602938739, RequestId: "FOZ8KyR7SejSKR8IWXk-JQ", IsFault: 0, FaultMessage: "None"

Regards

Google Ads API Forum Advisor

unread,
Jun 8, 2021, 10:13:38 PM6/8/21
to pipe...@gmail.com, adwor...@googlegroups.com
Hi,

I work with William and let me provide support to your concern.

To give more details about this error, this signifies that the access or refresh token being passed in your request is incorrect or invalid. Please note that the email address used to generate those credentials should have the appropriate access to the production account that you're trying to make an API request.

If you continue to encounter the said error while using email address that has the appropriate access to the production account, could you share with us the following details below via Reply privately to author option?

  • Email address (used to generate those credentials)
  • Customer ID (used for the API request)
  • Complete API logs (request and response) generated when the error occurred

If you haven't enabled the logging of API transactions for PHP client library, then you can follow this guide.

Regards,
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2HD6M1:ref
Reply all
Reply to author
Forward
0 new messages