fecing 'Google_Auth_Exception' wror fetching OAuth2 access token, message: 'invalid_client'' error

google-oauth, oauth-2.0, php

Solution

I had the same problem but my solution was extreamly easy and frustrating.

When you copy the "Client secret" in API Credentials on your Google Developers Console they add a space after the "Client secret". Be sure to delete it!

$client_secret = "hf83nd93hd93j39dj9 ";<--

Problem

I am trying to fetch mail from Google through gmail api while authenticate the Google_Client after receiving the token i am getting this error Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_client'' in my code is simple using google-api-php-client-master and my code is as follow ``` require_once('config.php'); require_once 'autoload.php'; $client = new Google_Client(); $client->setScopes(array( 'https://www.googleapis.com/auth/plus.login', 'profile', 'email', 'openid', 'https://www.googleapis.com/auth/gmail.readonly', 'https://mail.google.com/', )); $client->setApplicationName($config->social['google']->app_name); $client->setClientId($config->social['google']->client_id); $client->setClientSecret($config->social['google']->client_secret); $client->setRedirectUri($config->social['google']->Redirect_URI); $client->setDeveloperKey($config->social['google']->api_key); // API key $gclient=''; print_r($_GET); $token=new stdclass; if(!isset( $_SESSION['google_token'])) { $gclient=$client->authenticate($_GET['code']);//error occurs hare $_SESSION['gclient']=$gclient; if($gclient) { $_SESSION['google_token'] = $client->getAccessToken(); } print_r($gclient); ``` } I have checked my credentials several times and they were all correct would some one please help me on it

Original source