致命错误:未找到“Google \ Auth \ OAuth2”类

时间:2016-01-09 09:37:53

标签: php authentication

我正在尝试在google plus中实现登录。实际上我正在学习这些东西。请他;我解决这个问题。我知道这个问题已经发布在SOF中,但是没有一个确切的解决方案。

  

致命错误:未找到“Google \ Auth \ OAuth2”类

<?php 
            require_once __DIR__.'/gpluslib/vendor/autoload.php';
            const CLIENT_ID = 'id';
            const CLIENT_SECRET = 'secret';
    const REDIRECT_URI = 'http://localhost/home.php' ;
    session_start();

    $client = new Google_Client();
    $client->setClientId(CLIENT_ID);
    $client->setClientSecret(CLIENT_SECRET);
    $client->setRedirectUri(REDIRECT_URI);
    $client->setScopes('email');

    $plus = new Google_Service_Plus($client);

    if (isset($_REQUEST['logout'])) {
        session_unset();
    }
    if (isset($_GET['code'])) {
        $client->authenticate($_GET['code']);
        $_session['access_token'] = $client->getAccessToken();
        $redirect = 'http://'.$_server['HTTP_Host'].$_SERVER['PHP_SELF'];   
        header('Location'.filter_var($redirect,FILTER_SANITIZE_URL));
        }
    if(isset($_SESSION['access_token']) && $_SESSION['access_token']){
        $client->setAccessToken($_SESSION['access_token']);
        $me = $plus->people->get('me');
        $id = $me['id'];
        $name = $me['displayName'];

        }else{
            $authUrl = $client->createAuthUrl();
        }


    ?>
    <div>
    <?php 
       if(isset($authUrl)){
        echo "<a class='login' href='". $authUrl ."'><img src='dd.png' />";

          }
          else{
            print "ID:{$id} <br>";
            print "Name: {$name} ";
          }


    ?>
        </div>

0 个答案:

没有答案