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()); }
/** * Load the list of upcoming events in the UPL and return an array containing * an array of each event's information. */ function loadEvents() { if (!class_exists('apiClient')) { return array(); } // Load up the Google API client $client = new apiClient(); $client->setApplicationName('UPL Website'); $client->setUseObjects(true); apiKey($client); $cal = new apiCalendarService($client); // List all events in the UPL calendar $calendarId = '*****@*****.**'; $args = array('singleEvents' => true, 'orderBy' => 'startTime', 'maxResults' => 5, 'timeMin' => date(DateTime::RFC3339)); $events = $cal->events->listEvents($calendarId, $args); // Make sure that we at least have some events if (!$events) { return array(); } $events = $events->getItems(); if (!is_array($events)) { return array(); } // Just a little helper to convert dates function makeDate($evtDate) { return DateTime::createFromFormat(DateTime::RFC3339, $evtDate->getDateTime()); } function mapEvent($event) { return array('summary' => $event->getSummary(), 'start' => makeDate($event->getStart()), 'end' => makeDate($event->getEnd()), 'description' => $event->getDescription(), 'link' => $event->getHtmlLink()); } // Retrieve all our events return array_map(mapEvent, $events); }
/** * Build a Drive service object for interacting with the Google Drive API. * * @return apiDriveService service object */ function BuildService($credentials) { $client = new apiClient(); // return data from API calls as PHP objects instead of arrays $client->setUseObjects(true); $client->setAccessToken($credentials->toJson()); // set clientId and clientSecret in case token is expired // and refresh is needed $client->setClientId($credentials->clientId); $client->setClientSecret($credentials->clientSecret); return new apiDriveService($client); }
public static function getClient() { $client = new apiClient(); $client->setApplicationName('GAnalytics joomla extension'); $client->setClientId(GAnalyticsHelper::getComponentParameter('client-id')); $client->setClientSecret(GAnalyticsHelper::getComponentParameter('client-secret')); $uri = JFactory::getURI(); if (filter_var($uri->getHost(), FILTER_VALIDATE_IP)) { $uri->setHost('localhost'); } $client->setRedirectUri($uri->toString(array('scheme', 'host', 'port', 'path')) . '?option=com_ganalytics&view=import'); $client->setUseObjects(true); $service = new apiAnalyticsService($client); return $client; }
public function deleteGoogleCalendarEvent($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); $googleCalendar->events->delete($this->syncGoogleCalendarId, $action->syncGoogleCalendarEventId); } } } catch (Exception $e) { } }
/** * Retrieve user profile information from Google's UserInfo service. * * @param OauthCredentials $credentials Object representation of OAuth creds * @return Userinfo User profile information */ function GetUserInfo($credentials) { $client = new apiClient(); $client->setUseObjects(true); /* * Set clientId and clientSecret in case token is expired. * and refresh is needed */ $client->setClientId($credentials->clientId); $client->setClientSecret($credentials->clientSecret); $client->setAccessToken($credentials->toJson()); $userInfoService = new apiOauth2Service($client); $userInfo = $userInfoService->userinfo->get(); return $userInfo; }
* on the home page: I didn't want to mess with * Michael's code when I wasn't with him) was done * by Bobby. * *****************************************************/ session_start(); //include needed files require_once "google-api-php-client/src/apiClient.php"; require_once "google-api-php-client/src/contrib/apiCalendarService.php"; require_once("doodle-api/includes/helpers.php"); //create new API request $apiClient = new apiClient(); $apiClient->setUseObjects(true); $service = new apiCalendarService($apiClient); //set global for use later $_SESSION["service"]= $service; //check for current Authentication token if (isset($_SESSION['oauth_access_token'])) { $apiClient->setAccessToken($_SESSION['oauth_access_token']); } else { $token = $apiClient->authenticate(); $_SESSION['oauth_access_token'] = $token; }