Пример #1
0
$redirect_uri = $_SERVER['HTTP_HOST'] == 'localhost:13080' ? 'http://localhost:13080' : 'http://lyfekit.com';
require_once realpath(dirname(__FILE__) . '/autoload.php');
$client = new Google_Client();
$client->setApplicationName("LyfeKit");
// optional
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setApprovalPrompt('auto');
$client->setIncludeGrantedScopes(TRUE);
$client->setAccessType('offline');
$client->setScopes(array("https://www.googleapis.com/auth/plus.login", "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"));
if (isset($_SESSION['access_token']) && !empty($_SESSION['access_token'])) {
    $client->setAccessToken($_SESSION['access_token']);
    //print_r(array("action"=>"write","module"=>"google-login","content_style"=>"single_content","code"=>"","access_token"=>$_SESSION['access_token'],"request_from"=>"web"));
    $results = $ob->getApiContent($site_url . "/api/", 'array', array("action" => "write", "module" => "google-login", "content_style" => "single_content", "code" => "", "access_token" => $_SESSION['access_token'], "request_from" => "web"));
    //,"refresh_token"=>"1/rJd6RBEfmHV_Y_O5EUyuvqL73LFnSzNpiwOIBWsb8RYMEudVrK5jSpoR30zcRFq6"
    if ($results['status_code'] == 200) {
        $resp_data = json_decode($results['response'], TRUE);
        if (isset($resp_data['user_det'])) {
            $user_det = $resp_data['user_det'];
            $_SESSION['name'] = $user_det['name'];
            $_SESSION['gid'] = $user_det['id'];
            $_SESSION['email'] = $user_det['email'];
        } else {
            redirectto('#1');
        }
    } else {
        echo $results['response'];
    }
    // echo '<pre>';print_r($user_det); die();