Google Ads API, PHP: "Request had invalid authentication credentials. Expected OAuth 2 access token..." Error

10,154 views
Skip to first unread message

Κωστας Μαυρογαλος

unread,
Jun 19, 2023, 8:08:06 AM6/19/23
to Google Ads API and AdWords API Forum

I'm attempting to cURL the Google Ads API with the following PHP code:

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'developer-token: [DEVELOPER_TOKEN',
'login-customer-id: [LOGIN_CUSTOMER_ID]',
'Authorization: Bearer [???????]',
'Accept: application/json'
 'Content-Type: application/json', ]);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"historicalMetricsOptions":{"yearMonthRange":{"start":{"month":"JUNE","year":2022},"end":{"month":"MAY","year":2023}}},"keywords":[""]}');
$response = curl_exec($ch);
curl_close($ch);

And the response is:

{ "error": { "code": 401, "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

What I believe the issue to be is on the "Authentication" field. So far, I've put the following in that field(and failed each time):

  1. OAUTH 2 Client ID
  2. OAUTH 2 Client Secret
  3. OAUTH 2 Refresh Token, that works for another Google Ads project I've made
  4. Developer token

So, I could appreciate any and all help, since I'm running out of ideas and don't know what to do.

Google Ads API Forum Advisor

unread,
Jun 21, 2023, 9:34:32 AM6/21/23
to kostasma...@gmail.com, adwor...@googlegroups.com

Hi,

Thank you for reaching out to Google Ads API Forum.

I see that you encountered an error with the message: "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.” With this, could you try following the steps stated in this guide (https://developers.google.com/google-ads/api/docs/best-practices/troubleshooting#ensuring_connectivity) for best practices? Additionally, please check this documentation (https://developers.google.com/google-ads/api/docs/client-libs/php) for the guides in setting up the client library with OAuth. 

Furthermore, since you are using the latest API version which is v14, you may also check this reference (https://developers.google.com/google-ads/api/docs/client-libs#php) for the supported versions.

Please let us know how it goes. 

This message is in relation to case "ref:_00D1U1174p._5004Q2mVChA:ref"

Thanks,
 
Google Logo Google Ads API Team


Reply all
Reply to author
Forward
0 new messages