【问题标题】:Not able to resolve the following error from my code. Can someone explain?无法从我的代码中解决以下错误。有人可以解释吗?
【发布时间】:2020-03-06 05:53:17
【问题描述】:

致命错误:未捕获的 InvalidArgumentException:无效的令牌格式 在 C:\xampp\htdocs\GoogleLogin\GoogleAPI\src\Google\Client.php:449 堆栈跟踪:#0 C:\xampp\htdocs\GoogleLogin\g-callback.php(5): Google_Client->setAccessToken(Array) #1 {main} 抛出 C:\xampp\htdocs\GoogleLogin\GoogleAPI\src\Google\Client.php 上线 449

这是我的代码 sn-p:

<?php
    require_once "config.php";

    if(isset($_SESSION['access_token']))
        $gClient->setAccessToken($_SESSION['access_token']);
    elseif(isset($_GET['code'])){
        $token = $gClient->fetchAccessTokenWithAuthCode($_GET['code']);
        $_SESSION['access_token'] = $token;
    } else {
        header('Location: login.php');
        exit();
    }


    $oAuth = new Google_Service_Oauth2($gClient);
    $userData = $oAuth->userinfo_v2_me->get();


    $_SESSION['id'] = $userData['id'];
    $_SESSION['email'] = $userData['email'];
    $_SESSION['gender'] = $userData['gender'];
    $_SESSION['picture'] = $userData['picture'];
    $_SESSION['familyName'] = $userData['familyName'];
    $_SESSION['givenName'] = $userData['givenName'];

    header('Location: index.php');
    exit();

?>

【问题讨论】:

    标签: php localhost web-development-server


    【解决方案1】:

    检查$_SESSION['access_token'] 是否为空、null 或 false。您正在检查它是否存在,它显然必须存在,但这并不意味着它具有有效值。

    【讨论】:

      猜你喜欢
      • 2012-04-09
      • 2023-04-02
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 1970-01-01
      • 2020-05-29
      相关资源
      最近更新 更多