我正在尝试通过Gmail API从Google获取邮件。
在收到令牌后,身份验证Google_Client时,我遇到了以下错误:
致命错误:未捕获的异常'Google_Auth_Exception',错误消息为“获取OAuth2访问令牌时出错,消息为:'invalid_client'”
我的代码很简单,使用google-api-php-client-master,代码如下:
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);
}
我已经多次检查了我的凭据,它们都是正确的。
有人可以帮我吗?