首页 > 解决方案 > Google API 中的令牌格式无效

问题描述

当我想确保使用谷歌帐户登录时,我发现了一些错误。错误是:

致命错误:未捕获的 InvalidArgumentException:C:\xampp\htdocs\google\googleAPI\src\Google\Client.php:434 中的令牌格式无效 堆栈跟踪:#0 C:\xampp\htdocs\google\callback.php(5) : Google_Client->setAccessToken(Array) #1 {main} 在第 434 行的 C:\xampp\htdocs\google\googleAPI\src\Google\Client.php 中抛出

然后这是我的代码:

<?php   
require_once('config.php');

if (isset($_SESSION['accessToken'])){
    $client->setAccessToken($_SESSION['accessToken']);
}
else if (isset($_GET['code'])) {
    $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
    $_SESSION['accessToken'] = $token;


}
else{
    header("location: index.php");
}

$oAtuth = new Google_Service_Oauth2($client);
$user = $oAtuth->userinfo->get();

echo "<pre>";

print_r($user);

?>

请告诉我这段代码有什么问题

标签: phpmysqlgoogle-apigoogle-plusgoogle-api-client

解决方案


您在 中的令牌值错误$_SESSION['accessToken']


推荐阅读