public function actionDefault()
 {
     $google_config = NEnvironment::getConfig()->google;
     require_once LIBS_DIR . '/google-api-php-client/src/apiClient.php';
     require_once LIBS_DIR . '/google-api-php-client/src/contrib/apiOauth2Service.php';
     require_once LIBS_DIR . '/google-api-php-client/src/contrib/apiAnalyticsService.php';
     $client = new apiClient();
     $client->setApplicationName('Google+ PHP Starter Application');
     // Visit https://code.google.com/apis/console?api=plus to generate your
     // client id, client secret, and to register your redirect uri.
     //		$client->setClientId( $google_config['client_id'] );
     //		$client->setClientSecret( $google_config['client_secret'] );
     $client->setRedirectUri($google_config['redirect_url']);
     //		$client->setDeveloperKey('AIzaSyCrViGDrmXAiLsQAoW1aOzkHddH9gHYzzs');
     //		[8] => Array
     //        (
     //            [title] => www.propagacnepredmety.sk
     //            [entryid] => http://www.google.com/analytics/feeds/accounts/ga:43556790
     //            [accountId] => 17205615
     //            [accountName] => www.vizion.sk
     //            [profileId] => 43556790
     //            [webPropertyId] => UA-17205615-3
     //            [tableId] => ga:43556790
     //        )
     $ga = new apiAnalyticsService($client);
     if (isset($_GET['code'])) {
         $ga->authenticate();
         $_SESSION['token'] = $client->getAccessToken();
         header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if ($client->getAccessToken()) {
         $activities = $plus->activities->listActivities('me', 'public');
         print 'Your Activities: <pre>' . print_r($activities, true) . '</pre>';
         // The access token may have been updated.
         $_SESSION['token'] = $client->getAccessToken();
     } else {
         $authUrl = $client->createAuthUrl();
         print "<a class='login' href='{$authUrl}'>Connect Me!</a>";
     }
     //		$_SESSION['token'] = $client->getAccessToken();
     $data = $ga->data_ga;
     $d = $data->get('17205615', date('Y-m-d', time() - 60 * 60 * 24 * 40), date('Y-m-d', time() - 60 * 60 * 24 * 1), 'ga:visits,ga:pageviews');
     print_r($d);
     exit;
 }
Ejemplo n.º 2
0
 public function testSettersGetters()
 {
     $client = new apiClient();
     $client->setClientId("client1");
     $client->setClientSecret('client1secret');
     $client->setState('1');
     $client->setApprovalPrompt('force');
     $client->setAccessType('offline');
     global $apiConfig;
     $this->assertEquals('client1', $apiConfig['oauth2_client_id']);
     $this->assertEquals('client1secret', $apiConfig['oauth2_client_secret']);
     $client->setRedirectUri('localhost');
     $client->setApplicationName('me');
     $client->setUseObjects(false);
     $this->assertEquals('object', gettype($client->getAuth()));
     $this->assertEquals('object', gettype($client->getCache()));
     $this->assertEquals('object', gettype($client->getIo()));
     $client->setAuthClass('apiAuthNone');
     $client->setAuthClass('apiOAuth2');
     try {
         $client->setAccessToken(null);
         die('Should have thrown an apiAuthException.');
     } catch (apiAuthException $e) {
         $this->assertEquals('Could not json decode the access token', $e->getMessage());
     }
     $token = json_encode(array('access_token' => 'token'));
     $client->setAccessToken($token);
     $this->assertEquals($token, $client->getAccessToken());
 }
Ejemplo n.º 3
0
 public function index()
 {
     $this->id = "content";
     $this->template = "login/login.tpl";
     $this->layout = "common/layout";
     $request = Registry::get('request');
     $db = Registry::get('db');
     $session = Registry::get('session');
     $this->load->model('user/auth');
     $this->load->model('user/user');
     $this->load->model('user/prefs');
     $this->load->model('user/google');
     $this->load->model('domain/domain');
     $this->load->model('folder/folder');
     $this->document->title = $this->data['text_login'];
     $client = new apiClient();
     $client->setApplicationName(GOOGLE_APPLICATION_NAME);
     $client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://mail.google.com/'));
     $client->setClientId(GOOGLE_CLIENT_ID);
     $client->setClientSecret(GOOGLE_CLIENT_SECRET);
     $client->setRedirectUri(GOOGLE_REDIRECT_URL);
     $client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
     $oauth2 = new apiOauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate();
         $session->set("access_token", $client->getAccessToken());
         header('Location: ' . GOOGLE_REDIRECT_URL);
     }
     if ($session->get("access_token")) {
         $client->setAccessToken($session->get("access_token"));
     }
     if ($client->getAccessToken()) {
         $session->set("access_token", $client->getAccessToken());
         $token = json_decode($session->get("access_token"));
         if (isset($token->{'access_token'}) && isset($token->{'refresh_token'})) {
             $account = $oauth2->userinfo->get();
             $this->model_user_google->check_for_account($account);
             $this->model_user_google->update_tokens($account['email'], $account['id'], $token);
             header("Location: " . SITE_URL . "search.php");
             exit;
         }
     }
     $this->render();
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     global $apiConfig, $apiClient, $pageSpeedService;
     parent::__construct();
     if (!$apiClient || !$pageSpeedService) {
         $this->origConfig = $apiConfig;
         // Set up a predictable, default environment so the test results are predictable
         //$apiConfig['oauth2_client_id'] = 'INSERT_CLIENT_ID';
         //$apiConfig['oauth2_client_secret'] = 'INSERT_CLIENT_SECRET';
         $apiConfig['authClass'] = 'apiOAuth2';
         $apiConfig['ioClass'] = 'apiCurlIO';
         $apiConfig['cacheClass'] = 'apiFileCache';
         $apiConfig['ioFileCache_directory'] = '/tmp/googleApiTests';
         $apiClient = new apiClient();
         $pageSpeedService = new apiPagespeedonlineService($apiClient);
         if (!$apiClient->getAccessToken()) {
             $apiClient->setAccessToken($apiConfig['oauth_test_token']);
         }
     }
     $this->apiClient = $apiClient;
     $this->pageSpeedService = $pageSpeedService;
 }
Ejemplo n.º 5
0
 public function __construct()
 {
     global $apiConfig, $apiBuzzTest_apiClient, $apiBuzzTest_buzz;
     parent::__construct();
     if (!$apiBuzzTest_apiClient || !$apiBuzzTest_buzz) {
         $this->origConfig = $apiConfig;
         // Set up a predictable, default environment so the test results are predictable
         //$apiConfig['oauth2_client_id'] = 'INSERT_CLIENT_ID';
         //$apiConfig['oauth2_client_secret'] = 'INSERT_CLIENT_SECRET';
         $apiConfig['authClass'] = 'apiOAuth2';
         $apiConfig['ioClass'] = 'apiCurlIO';
         $apiConfig['cacheClass'] = 'apiFileCache';
         $apiConfig['ioFileCache_directory'] = '/tmp/googleApiTests';
         // create the global api and buzz clients (which are shared between the various buzz test suites for performance reasons)
         $apiBuzzTest_apiClient = new apiClient();
         $apiBuzzTest_buzz = new apiBuzzService($apiBuzzTest_apiClient);
         if (!$apiBuzzTest_apiClient->getAccessToken()) {
             $apiBuzzTest_apiClient->setAccessToken($apiConfig['oauth_test_token']);
         }
     }
     $this->apiClient = $apiBuzzTest_apiClient;
     $this->buzz = $apiBuzzTest_buzz;
 }
Ejemplo n.º 6
0
 public function refresh_access_token($email = '')
 {
     if ($email == '') {
         return '';
     }
     $query = $this->db->query("SELECT refresh_token FROM " . TABLE_GOOGLE . " WHERE email=?", array($email));
     if (!isset($query->row['refresh_token'])) {
         return '';
     }
     $client = new apiClient();
     $client->setApplicationName(GOOGLE_APPLICATION_NAME);
     $client->setClientId(GOOGLE_CLIENT_ID);
     $client->setClientSecret(GOOGLE_CLIENT_SECRET);
     $client->setRedirectUri(GOOGLE_REDIRECT_URL);
     $client->setDeveloperKey(GOOGLE_DEVELOPER_KEY);
     $client->refreshToken($query->row['refresh_token']);
     $s = $client->getAccessToken();
     $a = json_decode($s);
     if (isset($a->{'access_token'})) {
         return $a->{'access_token'};
     }
     return '';
 }
Ejemplo n.º 7
0
$client->setRedirectUri($config['googleRedirect']);
$client->setApprovalPrompt('auto');
//$oauth2 = new apiOauth2Service($client);
$db = new PDO($config['db'], $config['dbUser'], $config['dbPassword']);
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
$stmt = $db->prepare("SELECT `name`, `email`, `token` FROM `users`, `sessions` WHERE `sessions`.`user_id` = `users`.`id` AND `sessions`.`id` = :sessionId AND `users`.`id` = :userId LIMIT 1");
$stmt->execute(array(':userId' => $userId, ':sessionId' => $sessionId));
$user = $stmt->fetch();
if (!$user) {
    setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
    echo json_encode(array('status' => 'error', 'message' => 'wrong session'));
    exit;
}
$token = $user->token;
$client->setAccessToken($token);
$token = $client->getAccessToken();
if (!$token) {
    setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
    $stmt = $db->prepare("DELETE FROM `sessions` WHERE `id` = :sessionId");
    $stmt->execute(array(':sessionId' => $sessionId));
    echo json_encode(array('status' => 'error', 'message' => 'session mismatch'));
    exit;
}
// Update session id and token
$newSessionId = sha1(uniqid($userId, true) . $user->email . $config['salt']);
$stmt = $db->prepare("UPDATE `sessions` SET `id` = :newSessionId, `token` = :token WHERE `id` = :sessionId");
$stmt->execute(array(':newSessionId' => $newSessionId, ':token' => $token, ':sessionId' => $sessionId));
setcookie('hexauser', $userId . '+' . $newSessionId, time() + 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']);
// Get highscore
//$stmt = $db->prepare( "SELECT `score` FROM `scoreboards` WHERE `user_id` = :userId ORDER BY `score` DESC LIMIT 1" );
$stmt = $db->prepare("SELECT MAX(`score`) AS `score`, MAX(`level`) AS `level` FROM `scoreboards` WHERE `user_id` = :userId");
Ejemplo n.º 8
0
require_once '../../src/apiClient.php';
require_once '../../src/contrib/apiUrlshortenerService.php';
// Visit https://code.google.com/apis/console to
// generate your client id, client secret, and redirect uri.
$client = new apiClient();
$client->setClientId('insert_your_oauth2_client_id');
$client->setClientSecret('insert_your_oauth2_client_secret');
$client->setRedirectUri('insert_your_oauth2_redirect_uri');
$service = new apiUrlshortenerService($client);
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['access_token'] = $client->getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
    $client->setAccessToken($_SESSION['access_token']);
} else {
    $authUrl = $client->createAuthUrl();
}
if ($client->getAccessToken() && isset($_GET['url'])) {
    // Start to make API requests.
    $url = new Url();
    $url->longUrl = $_GET['url'];
    $short = $service->url->insert($url);
    $_SESSION['access_token'] = $client->getAccessToken();
}
?>
Ejemplo n.º 9
0
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
// $client->setClientId('insert_your_oauth2_client_id');
// $client->setClientSecret('insert_your_oauth2_client_secret');
// $client->setRedirectUri('insert_your_oauth2_redirect_uri');
// $client->setApplicationName("Tasks_Example_App");
$tasksService = new apiTasksService($client);

if (isset($_REQUEST['logout'])) {
  unset($_SESSION['access_token']);
}

if (isset($_SESSION['access_token'])) {
  $client->setAccessToken($_SESSION['access_token']);
} else {
  $client->setAccessToken($client->authenticate());
  $_SESSION['access_token'] = $client->getAccessToken();
}

if (isset($_GET['code'])) {
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
?>
<!doctype html>
<html>
<head>
  <title>Tasks API Sample</title>
  <link rel='stylesheet' href='http://fonts.googleapis.com/css?family=Droid+Serif|Droid+Sans:regular,bold' />
  <link rel='stylesheet' href='css/style.css' />
</head>
<body>
<div id='container'>
Ejemplo n.º 10
0
function gplus_init_auth()
{
    gplus_load();
    $client = new apiClient();
    $oauth2 = new apiOauth2Service($client);
    if (isset($_GET['code'])) {
        $client->authenticate();
        $_SESSION['token'] = $client->getAccessToken();
    }
    if (isset($_SESSION['token'])) {
        $client->setAccessToken($_SESSION['token']);
    }
    if ($client->getAccessToken()) {
        $user = $oauth2->userinfo->get();
        $_SESSION['token'] = $client->getAccessToken();
    }
    if (isset($user) && isset($_GET['code'])) {
        $_SESSION['gplusdata'] = $user;
        $_SESSION['gplus']['idm'] = $user['id'];
        $_SESSION['gplus']['pic'] = !empty($user['picture']) ? $user['picture'] : '';
        redirectexit('action=gplus;auth=done');
    }
}
Ejemplo n.º 11
0
<?php

session_start();
require_once "../src/apiClient.php";
$client = new apiClient();
$client->discover('plus');
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
}
if (isset($_GET['code'])) {
    $client->authenticate();
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
    $ret = apiBatch::execute($client->plus->activities->list(array('userId' => 'me', 'collection' => 'public'), 'listActivities'), $client->plus->people->get(array('userId' => 'me'), 'getPerson'));
    print "<pre>" . print_r($ret, true) . "</pre>";
} else {
    $client->authenticate();
}
Ejemplo n.º 12
0
 public function index()
 {
     session_start();
     $client = new apiClient();
     $redirectUri = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
     $client->setApplicationName('PHP, YouTube, OAuth2, and CodeIgniter Example');
     $client->setClientId(CLIENT_ID);
     $client->setClientSecret(CLIENT_SECRET);
     $client->setRedirectUri($redirectUri);
     $client->setDeveloperKey(DEVELOPER_KEY);
     new apiPlusService($client);
     // Sets the OAuth2 scope.
     $this->load->library('youtube', array('apikey' => YOUTUBE_API_KEY));
     // This example doesn't require authentication:
     // header("Content-type: text/plain");
     // echo "Here is the output:\n";
     // echo $this->youtube->getKeywordVideoFeed('pac man');
     if (isset($_GET['code'])) {
         $client->authenticate();
         $_SESSION['token'] = $client->getAccessToken();
         header("Location: {$redirectUri}");
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if (!$client->getAccessToken()) {
         $authUrl = $client->createAuthUrl();
         echo "<a class='login' href='{$authUrl}'>Connect Me!</a>";
     } else {
         // The access token may have been updated lazily.
         $_SESSION['token'] = $client->getAccessToken();
         header("Content-type: text/plain");
         $accessToken = json_decode($_SESSION['token'])->access_token;
         echo "Here is the output:\n";
         echo $this->youtube->getUserUploads('default', array('access_token' => $accessToken, 'prettyprint' => 'true'));
     }
 }
Ejemplo n.º 13
0
 public function __destruct()
 {
     global $apiConfig;
     $apiConfig['oauth_test_token'] = self::$client->getAccessToken();
 }
Ejemplo n.º 14
0
    font-weight:bolder;
}
strong{
    font-weight:bolder;
}
img{
    display:none;
}
ul{
  font-style: italic;
}
</style>
</head>
<body>
HTML;
if ($client->getAccessToken()) {
    $req = new apiHttpRequest("http://www.google.com/reader/api/0/stream/contents/?xt=user/-/state/com.google/read&n=50");
    $val = $client->getIo()->authenticatedRequest($req);
    $response = json_decode($val->getResponseBody(), true);
    foreach ($response['items'] as $item) {
        $html .= '<h2>' . $item['title'] . '</h2>' . "\n";
        $html .= '<p class="info">作者:' . @$item['author'] . '  发表时间:' . date('Y-m-d H:i:s', $item['published'] + 8 * 3600) . ' </p>' . "\n";
        if (isset($item['summary']['content'])) {
            $content = $item['summary']['content'];
        } else {
            @($content = $item['content']['content']);
        }
        $html .= '<div class="entry">' . $content . '</div><mbp:pagebreak />' . "\n";
    }
}
$html .= <<<HTML
Ejemplo n.º 15
0
 public function actionSyncActionsToGoogleCalendar()
 {
     $model = Yii::app()->params->profile;
     if (isset($_POST['ProfileChild'])) {
         foreach (array_keys($model->attributes) as $field) {
             if (isset($_POST['ProfileChild'][$field])) {
                 $model->{$field} = $_POST['ProfileChild'][$field];
             }
         }
         if ($model->syncGoogleCalendarId && isset($_SESSION['token'])) {
             $token = json_decode($_SESSION['token'], true);
             $model->syncGoogleCalendarRefreshToken = $token['refresh_token'];
             // used for accessing this google calendar at a later time
             $model->syncGoogleCalendarAccessToken = $_SESSION['token'];
         }
         $model->update();
     }
     $admin = Yii::app()->params->admin;
     $googleIntegration = $admin->googleIntegration;
     // if google integration is activated let user choose if they want to link this calendar to a google calendar
     if ($googleIntegration) {
         $timezone = date_default_timezone_get();
         require_once "protected/extensions/google-api-php-client/src/apiClient.php";
         require_once "protected/extensions/google-api-php-client/src/contrib/apiCalendarService.php";
         date_default_timezone_set($timezone);
         $client = new apiClient();
         $syncGoogleCalendarName = null;
         // name of the Google Calendar that current user's actions are being synced to if it has been set
         if (isset($_GET['unlinkGoogleCalendar'])) {
             // user changed thier mind about linking their google calendar
             unset($_SESSION['token']);
             $model->syncGoogleCalendarId = null;
             $model->syncGoogleCalendarRefreshToken = null;
             // used for accessing this google calendar at a later time
             $model->syncGoogleCalendarAccessToken = null;
             $model->update();
             $googleCalendarList = null;
             $client->setApplicationName("Google Calendar Integration");
             // Visit https://code.google.com/apis/console?api=calendar to generate your
             // client id, client secret, and to register your redirect uri.
             $client->setClientId($admin->googleClientId);
             $client->setClientSecret($admin->googleClientSecret);
             $client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl(''));
             $client->setDeveloperKey($admin->googleAPIKey);
             $client->setAccessType('offline');
             $googleCalendar = new apiCalendarService($client);
             if (isset($_GET['code'])) {
                 // returning from google with access token
                 $client->authenticate();
                 $_SESSION['token'] = $client->getAccessToken();
                 header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
             }
             if (isset($_SESSION['token'])) {
                 $client->setAccessToken($_SESSION['token']);
                 $calList = $googleCalendar->calendarList->listCalendarList();
                 $googleCalendarList = array();
                 foreach ($calList['items'] as $cal) {
                     $googleCalendarList[$cal['id']] = $cal['summary'];
                 }
             } else {
                 $googleCalendarList = null;
             }
         } else {
             if ($model->syncGoogleCalendarRefreshToken) {
                 $client->setClientId($admin->googleClientId);
                 $client->setClientSecret($admin->googleClientSecret);
                 $client->setDeveloperKey($admin->googleAPIKey);
                 $client->setAccessToken($model->syncGoogleCalendarAccessToken);
                 $googleCalendar = new apiCalendarService($client);
                 // check if the access token needs to be refreshed
                 // note that the google library automatically refreshes the access token if we need a new one,
                 // we just need to check if this happend by calling a google api function that requires authorization,
                 // and, if the access token has changed, save this new access token
                 $testCal = $googleCalendar->calendars->get($model->syncGoogleCalendarId);
                 if ($model->syncGoogleCalendarAccessToken != $client->getAccessToken()) {
                     $model->syncGoogleCalendarAccessToken = $client->getAccessToken();
                     $model->update();
                 }
                 $calendar = $googleCalendar->calendars->get($model->syncGoogleCalendarId);
                 $syncGoogleCalendarName = $calendar['summary'];
                 $calList = $googleCalendar->calendarList->listCalendarList();
                 $googleCalendarList = array();
                 foreach ($calList['items'] as $cal) {
                     $googleCalendarList[$cal['id']] = $cal['summary'];
                 }
             } else {
                 $client->setApplicationName("Google Calendar Integration");
                 // Visit https://code.google.com/apis/console?api=calendar to generate your
                 // client id, client secret, and to register your redirect uri.
                 $client->setClientId($admin->googleClientId);
                 $client->setClientSecret($admin->googleClientSecret);
                 $client->setRedirectUri((@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $this->createUrl(''));
                 $client->setDeveloperKey($admin->googleAPIKey);
                 $client->setAccessType('offline');
                 $googleCalendar = new apiCalendarService($client);
                 if (isset($_GET['code'])) {
                     // returning from google with access token
                     $client->authenticate();
                     $_SESSION['token'] = $client->getAccessToken();
                     header('Location: ' . (@$_SERVER['HTTPS'] == 'on' ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
                 }
                 if (isset($_SESSION['token'])) {
                     $client->setAccessToken($_SESSION['token']);
                     $calList = $googleCalendar->calendarList->listCalendarList();
                     $googleCalendarList = array();
                     foreach ($calList['items'] as $cal) {
                         $googleCalendarList[$cal['id']] = $cal['summary'];
                     }
                 } else {
                     $googleCalendarList = null;
                 }
             }
         }
     } else {
         $client = null;
         $googleCalendarList = null;
     }
     $this->render('syncActionsToGoogleCalendar', array('model' => $model, 'googleIntegration' => $googleIntegration, 'client' => $client, 'googleCalendarList' => $googleCalendarList, 'syncGoogleCalendarName' => $syncGoogleCalendarName));
 }
Ejemplo n.º 16
0
require_once 'src/apiClient.php';
session_start();

$client = new apiClient();
$client -> setApplicationName('Google Contacts');
$client -> setScopes("http://www.google.com/m8/feeds/");
$client -> setClientId(GOOGLE_CLIENT_ID);
$client -> setClientSecret(GOOGLE_CLIENT_SECRET);
$client -> setRedirectUri(AUTH_BASE_URL . '/gmail/index.php');

//$client->setDeveloperKey('insert_your_developer_key');

if (isset($_GET['code']))
{
	$client -> authenticate();
	$_SESSION['token'] = $client -> getAccessToken();
}

$match = false;

if (isset($_SESSION['token']))
{
	try{
		$client -> setAccessToken($_SESSION['token']);
		$match = true;
	}catch(Exception $ex){
		$match = false;
	}
	
}
Ejemplo n.º 17
0
$plus = new apiPlusService($client);
if (isset($_REQUEST['logout'])) {
    $files = glob('images/*');
    // get all file names
    foreach ($files as $file) {
        // iterate files
        if (is_file($file)) {
            unlink($file);
        }
        // delete file
    }
    unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
    $client->authenticate();
    $_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'])) {
    $client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken()) {
    $myFile = "updated.txt";
    $fh = fopen($myFile, 'r');
    $last_time = fgets($fh);
    fclose($fh);
    $pw_content = "";
    $me = $plus->people->get('me');
    $url = filter_var($me['url'], FILTER_VALIDATE_URL);
    $img = filter_var($me['image']['url'], FILTER_VALIDATE_URL);
Ejemplo n.º 18
0
 public function getGoogleCalendar()
 {
     // Google Calendar Libraries
     $timezone = date_default_timezone_get();
     require_once "protected/extensions/google-api-php-client/src/apiClient.php";
     require_once "protected/extensions/google-api-php-client/src/contrib/apiCalendarService.php";
     date_default_timezone_set($timezone);
     $admin = Yii::app()->params->admin;
     if ($admin->googleIntegration) {
         $client = new apiClient();
         $client->setClientId($admin->googleClientId);
         $client->setClientSecret($admin->googleClientSecret);
         $client->setDeveloperKey($admin->googleAPIKey);
         $client->setAccessToken($this->googleAccessToken);
         $service = new apiCalendarService($client);
         // check if the access token needs to be refreshed
         // note that the google library automatically refreshes the access token if we need a new one,
         // we just need to check if this happend by calling a google api function that requires authorization,
         // and, if the access token has changed, save this new access token
         $googleCalendar = $service->calendars->get($this->googleCalendarId);
         if ($this->googleAccessToken != $client->getAccessToken()) {
             $this->googleAccessToken = $client->getAccessToken();
             $this->update();
         }
         return $service;
     }
     return null;
 }
Ejemplo n.º 19
0
<?php

require_once 'src/apiClient.php';
require_once 'src/contrib/apiPlusService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("Kindle Reader");
$client->setScopes(array('https://www.google.com/reader/api'));
if (isset($_REQUEST['logout'])) {
    unset($_SESSION['access_token']);
}
if (isset($_GET['code'])) {
    $client->authenticate();
    $_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'])) {
    $client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken()) {
    $_SESSION['access_token'] = $client->getAccessToken();
    header('Location: sender.php');
} else {
    $status = "Logged Out";
    $authUrl = $client->createAuthUrl();
    header('Location: ' . $authUrl);
}
Ejemplo n.º 20
0
 public function updateGoogleCalendarEvent($action)
 {
     try {
         // catch google exceptions so the whole app doesn't crash if google has a problem syncing
         $admin = Yii::app()->params->admin;
         if ($admin->googleIntegration) {
             if (isset($this->syncGoogleCalendarId) && $this->syncGoogleCalendarId) {
                 // Google Calendar Libraries
                 $timezone = date_default_timezone_get();
                 require_once "protected/extensions/google-api-php-client/src/apiClient.php";
                 require_once "protected/extensions/google-api-php-client/src/contrib/apiCalendarService.php";
                 date_default_timezone_set($timezone);
                 $client = new apiClient();
                 $client->setClientId($admin->googleClientId);
                 $client->setClientSecret($admin->googleClientSecret);
                 $client->setDeveloperKey($admin->googleAPIKey);
                 $client->setAccessToken($this->syncGoogleCalendarAccessToken);
                 $client->setUseObjects(true);
                 // return objects instead of arrays
                 $googleCalendar = new apiCalendarService($client);
                 // check if the access token needs to be refreshed
                 // note that the google library automatically refreshes the access token if we need a new one,
                 // we just need to check if this happend by calling a google api function that requires authorization,
                 // and, if the access token has changed, save this new access token
                 $testCal = $googleCalendar->calendars->get($this->syncGoogleCalendarId);
                 if ($this->syncGoogleCalendarAccessToken != $client->getAccessToken()) {
                     $this->syncGoogleCalendarAccessToken = $client->getAccessToken();
                     $this->update();
                 }
                 $summary = $action->actionDescription;
                 if ($action->associationType == 'contacts' || $action->associationType == 'contact') {
                     $summary = $action->associationName . ' - ' . $action->actionDescription;
                 }
                 $event = $googleCalendar->events->get($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId);
                 $event->setSummary($summary);
                 if ($action->allDay) {
                     $start = new EventDateTime();
                     $start->setDate(date('Y-m-d', $action->dueDate));
                     $event->setStart($start);
                     if (!$action->completeDate) {
                         $action->completeDate = $action->dueDate;
                     }
                     $end = new EventDateTime();
                     $end->setDate(date('Y-m-d', $action->completeDate + 86400));
                     $event->setEnd($end);
                 } else {
                     $start = new EventDateTime();
                     $start->setDateTime(date('c', $action->dueDate));
                     $event->setStart($start);
                     if (!$action->completeDate) {
                         $action->completeDate = $action->dueDate;
                     }
                     // if no end time specified, make event 1 hour long
                     $end = new EventDateTime();
                     $end->setDateTime(date('c', $action->completeDate));
                     $event->setEnd($end);
                 }
                 if ($action->color && $action->color != '#3366CC') {
                     $colorTable = array(10 => 'Green', 11 => 'Red', 6 => 'Orange', 8 => 'Black');
                     if (($key = array_search($action->color, $colorTable)) != false) {
                         $event->setColorId($key);
                     }
                 }
                 $newEvent = $googleCalendar->events->update($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId, $event);
             }
         }
     } catch (Exception $e) {
     }
 }