Google_客户端()->;验证($code)错误无效\u授予php

Google_客户端()->;验证($code)错误无效\u授予php,php,api,google-client,Php,Api,Google Client,首先请原谅我的英语很差。。。 我的问题是:Google_客户端类的“authenticate($code)”方法的参数应该是什么??? 我已将电子邮件地址写入web应用程序的客户端ID;接下来,我已将客户端ID写入,并始终返回错误“invalid_grant” 这就是错误所在 [Tue Apr 22 10:22:19 2014] [error] [client 127.0.0.1] PHP Fatal error: Uncaught exception 'Google_Auth_Excepti

首先请原谅我的英语很差。。。 我的问题是:Google_客户端类的“authenticate($code)”方法的参数应该是什么??? 我已将电子邮件地址写入web应用程序的客户端ID;接下来,我已将客户端ID写入,并始终返回错误“invalid_grant”

这就是错误所在

[Tue Apr 22 10:22:19 2014] [error] [client 127.0.0.1] PHP Fatal error:  Uncaught exception 'Google_Auth_Exception' with message 'Error fetching OAuth2 access token, message: 'invalid_grant'' in /var/www/Repartos/Google/Auth/OAuth2.php:124\nStack trace:\n#0 /var/www/Repartos/Google/Client.php(136): Google_Auth_OAuth2->authenticate('499123288166@de...')\n#1 /var/www/Repartos/index.php(36): Google_Client->authenticate('499123288166@de...')\n#2 {main}\n  thrown in /var/www/Repartos/Google/Auth/OAuth2.php on line 124
这是我的密码

<?php
// put your code here

//Incluimos la ubicación de las librerías para poder utilizarlo en nuestra app
session_start();
require_once 'Google/Client.php';
require_once 'Google/Service.php';
require_once 'Google/Service/Tasks.php';
// Creamos el objeto de la API de Google, primero un objeto de la clase Client
$cliente = new Google_Client();
$idCliente ='xxxxxx';
$secertCliente='xxxxx';
$key='xxxxx';
// Y lo configuramos con los nuestros identificadores
$cliente->setApplicationName("Gestor de repartos");
$cliente->setClientId('$IdCliente');
$cliente->setClientSecret('·$secertClient');  
$cliente->setRedirectUri('http://localhost/Repartos/index.php');
$cliente->setDeveloperKey('$key');
$cliente->setScopes(array('https://www.googleapis.com/auth/tasks'));
$apitareas = new Google_Service_Tasks($cliente);

//Ahora nos autentificamos

if (isset($_SESSION['clave_acceso'])) {
   $cliente->setAccessToken($_SESSION['clave_acceso']);
} else {
 //Petada total al utentificarse
$cliente->setAccessToken($cliente->authenticate('$code'));
$_SESSION['clave_acceso'] = $cliente->getAccessToken();
}

我认为您必须使用$\u GET['code'中的值
  /**
   * Attempt to exchange a code for an valid authentication token.
   * Helper wrapped around the OAuth 2.0 implementation.
   *
   * @param $code string code from accounts.google.com
   * @return string token
   */
  public function authenticate($code)
  {
    $this->authenticated = true;
    return $this->getAuth()->authenticate($code);
  }