Ejemplo n.º 1
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.º 2
0
 /**
  * Constructor and Login
  * @param $buy
  * @return Oara_Network_Publisher_Buy_Api
  */
 public function __construct($credentials)
 {
     $client = new apiClient();
     $client->setApplicationName("AffJet");
     $client->setClientId($credentials['clientId']);
     $client->setClientSecret($credentials['clientSecret']);
     $client->setAccessToken($credentials['oauth2']);
     $client->setAccessType('offline');
     $this->_client = $client;
     $this->_gan = new apiGanService($client);
 }
<?php

session_start();
/******Improting Facebook API Files**************/
require_once 'includes/google-api-php-client/apiClient.php';
require_once 'includes/google-api-php-client/contrib/apiOauth2Service.php';
require_once 'credentials.php';
require_once 'sqlFunctions.php';
/******Google API Connection With My APP**************/
$client = new apiClient();
//$client->setApplicationName("TheASP");
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setDeveloperKey($api_key);
$client->setRedirectUri($redirect_url);
$client->setAccessType('online');
$client->setApprovalPrompt('auto');
$oauth2 = new apiOauth2Service($client);
/******Waiting For OAuth Token And Then Authenticating**************/
if (isset($_GET['code'])) {
    $client->authenticate();
    /******After Authentication Requesting For User Data******/
    $info = $oauth2->userinfo->get();
    //echo '<pre>' . print_r( $info, 1 ) . '</pre>';
}
$email = $info['email'];
$fullname = $info['name'];
$fname = $info['given_name'];
$lname = $info['family_name'];
$Fuid = $info['id'];
$fblink = $info['link'];
Ejemplo n.º 4
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));
 }