joced nieves joced nieves - 10 months ago 64
PHP Question

Uncaught exception 'InvalidArgumentException' with message 'invalid json token'

Hello I have a problem trying to use google/apiclient

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'invalid json token' in C:\xampp\htdocs\Google\vendor\google\apiclient\src\Google\Client.php:422 Stack trace: #0 C:\xampp\htdocs\Google\app\class\google_auth.php(43): Google_Client->setAccessToken(NULL) #1 C:\xampp\htdocs\Google\app\class\google_auth.php(34): GoogleAuth->setToken(NULL) #2 C:\xampp\htdocs\Google\index.php(10): GoogleAuth->checkRedirectCode() #3 {main} thrown in C:\xampp\htdocs\Google\vendor\google\apiclient\src\Google\Client.php on line 422

My index:


$googleClient = new Google_Client();
$auth = new GoogleAuth($googleClient);

if ($auth->checkRedirectCode()) {
header("Location: index.php");


<!DOCTYPE html>

<?php if (!$auth->isLoggedIn()): var_dump($auth->isLoggedIn()); //Verificar Inicio de Sesion ?>
<a href="<?php echo $auth->getAuthUrl(); ?>">Inicie Sesion con Google</a>
<?php else: //Si no ha iniciado Sesion ?>
Bienvenido.. <a href="logout.php">Cerrar Sesion</a>
<?php endif; ?>


The class GoogleAuth:


class GoogleAuth{//Clase para la autenticacion del usuario google

protected $client;//Variable de cliente

public function __construct(Google_Client $googleClient = null){
$this->client = $googleClient;

if ($this->client) {

$this->client->setClientId('');//Usuario Auth Google
bMuLusxZW6ohlI3vnvPg2zRz');//Clave Auth Google


public function isLoggedIn(){//Metodo que devuelve el estatus de la Sesion con Google (true o false)
return isset($_SESSION['access_token']);


public function getAuthUrl(){//Funcion que devuelve el enlace requerido para iniciar sesion
return $this->client->createAuthUrl();


public function checkRedirectCode(){
if (isset($_GET['code'])) {

return true;
return false;

public function setToken($token){

public function logout(){



is returning

Answer Source

To me it looks like the issue might be here

                bMuLusxZW6ohlI3vnvPg2zRz');//Clave Auth Google

Unless that is a copy/paste error.

$this->client->setClientSecret('bMuLusxZW6ohlI3vnvPg2zRz');//Clave Auth Google

This is what I would do to fix it, first.