// configuration of client credentials
$client = new OAuth2\Client('CLIENT_ID', 'CLIENT_SECRET', 'CALLBACK_URL');
// or use without callback_url, use in desktop application
$client = new OAuth2\Client('CLIENT_ID', 'CLIENT_SECRET');
// configuration of service
$configuration = new OAuth2\Service\Configuration('AUTHORIZE_ENDPOINT', 'ACCESS_TOKEN_ENDPOINT', 'REVOKE_ENDPOINT');
// storage class for access token, just implement OAuth2\DataStore interface for
// your own implementation
$dataStore = new OAuth2\DataStore\Session();
$scope = null;
$service = new OAuth2\Service($client, $configuration, $dataStore, $scope);
if (isset($_GET['action'])) {
    switch ($_GET['action']) {
        case 'authorize':
            // redirects to authorize endpoint
            $service->authorize();
            break;
        case 'requestApi':
            // calls api endpoint with access token
            echo $service->callApiEndpoint('API_ENDPOINT');
            break;
        case 'revoke':
            // calls revoke access token
            echo $service->revokeAccessToken();
            break;
    }
}
if (isset($_GET['code'])) {
    // retrieve access token from endpoint
    $service->getAccessToken();
}
 public function google_oauth2()
 {
     //'http://cp-dev.cis.fiu.edu/coplat/index.php/site/login?r=Login/google_oauth2_callback'
     $client = new OAuth2\Client('265213885628-bvag1ur2vpn9a1asmagjn4rtb624p0l2.apps.googleusercontent.com', 'UwkqyyRLy0I_sJXwZ_JqurVh', getAuthorizationCallbackURL());
     //104217401955-72dtm4gbmujaca9bjl90ohg03lp22cqs.apps.googleusercontent.com
     //PbZgJPfW7sBHOcyMEHmhdcM-
     $configuration = new OAuth2\Service\Configuration('https://accounts.google.com/o/oauth2/auth', 'https://accounts.google.com/o/oauth2/auth/token');
     $dataStore = new OAuth2\DataStore\Session();
     $scope = "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
     $service = new OAuth2\Service($client, $configuration, $dataStore, $scope);
     $service->authorize();
 }