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; }
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()); }
public function __construct() { parent::__construct(); if (!BaseTest::$client) { global $apiConfig; $apiConfig['ioFileCache_directory'] = '/tmp/google-api-php-client/tests'; BaseTest::$client = new apiClient(); if (!BaseTest::$client->getAccessToken()) { BaseTest::$client->setAccessToken($apiConfig['oauth_test_token']); } } }
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); $apiBuzzTest_apiClient->setAccessToken($apiConfig['oauth_test_token']); } $this->apiClient = $apiBuzzTest_apiClient; $this->buzz = $apiBuzzTest_buzz; }
public static function getServiceClient() { if (!self::isServiceConfigured()) { return false; } $config = self::getConfig(); $client = new apiClient(array("ioFileCache_directory" => PIMCORE_CACHE_DIRECTORY)); $client->setApplicationName("pimcore CMF"); $key = file_get_contents(self::getPrivateKeyPath()); $client->setAssertionCredentials(new apiAssertionCredentials($config->email, array('https://www.googleapis.com/auth/analytics.readonly', "https://www.google.com/webmasters/tools/feeds/"), $key)); $client->setClientId($config->client_id); // token cache $tokenFile = PIMCORE_SYSTEM_TEMP_DIRECTORY . "/google-api.token"; if (file_exists($tokenFile)) { $tokenData = file_get_contents($tokenFile); $tokenInfo = Zend_Json::decode($tokenData); if ($tokenInfo["created"] + $tokenInfo["expires_in"] > time() - 900) { $token = $tokenData; } } if (!$token) { $client->getAuth()->refreshTokenWithAssertion(); $token = $client->getAuth()->getAccessToken(); file_put_contents($tokenFile, $token); } $client->setAccessToken($token); return $client; }
/** * 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); }
/** * 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 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(); }
public function __construct() { global $apiConfig, $apiClient, $taskService; parent::__construct(); if (! $apiClient || ! $taskService) { $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(); $taskService = new apiTasksService($apiClient); $apiClient->setAccessToken($apiConfig['oauth_test_token']); } $this->apiClient = $apiClient; $this->taskService = $taskService; }
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')); } }
/** * @depends testGetPublicStream */ public function testUnauthenticatedStream() { global $apiConfig; // test unauthenticated public stream fetching $apiConfig['authClass'] = 'apiAuthNone'; $apiClient = new apiClient(); $buzz = new apiBuzzService($apiClient); $apiClient->setAccessToken($apiConfig['oauth_test_token']); // fetch the unauthenticated, public activity streamn $activities = $buzz->listActivities('@public', $apiConfig['oauth_test_user']); // and evaluate it $this->evaluateActivitiesStream($activities); // restore the default Auth class & clean up $apiConfig['authClass'] = 'apiOAuth'; unset($buzz); unset($apiClient); unset($activities); }
$client = new apiClient(); // Visit https://code.google.com/apis/console to generate your // 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' />
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; }
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; }
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'); } }
$client->setClientSecret($config['googleSecret']); $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" );
* Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ // Include the Google API Client library, and the Buzz Service wrapper require_once "google-api-php-client/src/apiClient.php"; require_once "google-api-php-client/src/contrib/apiBuzzService.php"; // Setup the API Client, and create the Buzz client using it $apiClient = new apiClient(); $buzz = new apiBuzzService($apiClient); // If a oauth token was stored in the session, use that- and otherwise go through the oauth dance if (isset($_SESSION['auth_token'])) { $apiClient->setAccessToken($_SESSION['auth_token']); } else { // In a real application this would be stored in a database, and not in the session! $_SESSION['auth_token'] = $apiClient->authenticate(); }
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)); }
unset($_SESSION["access_token"]); header("Location: " . $base_url); } $request = $_SERVER["REQUEST_URI"]; $path = $_SERVER["PHP_SELF"]; $p = strrpos($path, "/"); if (!($p === false)) { $request = substr($request, $p + 1); $path = substr($path, 0, $p); } $q_user = ""; if (substr($request, 0, 1) == "u") { $q_user = substr($request, 2); } if (isset($_SESSION["access_token"])) { $client->setAccessToken($_SESSION["access_token"]); } if ($client->getAccessToken()) { try { $me = $plus->people->get('me'); $_SESSION["access_token"] = $client->getAccessToken(); if ($q_user == "") { header("Location: " . $base_url . "u/" . $me["id"]); } $login_id = $me["id"]; $login_name = $me["displayName"]; } catch (Exception $e) { unset($_SESSION["access_token"]); $authUrl = $client->createAuthUrl(); $authUrl = str_replace("&", "&", $authUrl); $authUrl = str_replace("&", "&", $authUrl);
$stmt = $db->prepare("DELETE FROM `sessions` WHERE `id` = :sessionId"); $stmt->execute(array(':sessionId' => $sessionId)); } } setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']); } $client = new apiClient(); $client->setApplicationName('Hexagame'); $client->setClientId($config['googleId']); $client->setClientSecret($config['googleSecret']); $client->setRedirectUri($config['googleRedirect']); $client->setApprovalPrompt('auto'); $oauth2 = new apiOauth2Service($client); if (isset($_GET['logout'])) { if ($session) { $client->setAccessToken($session->token); $client->revokeToken(); } $redirect = 'http://' . $_SERVER['HTTP_HOST']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); exit; } if (isset($_GET['code'])) { $client->authenticate(); $token = $client->getAccessToken(); if ($token) { $googleUser = $oauth2->userinfo->get(); // Search the email in the database $stmt = $db->prepare("SELECT `id` FROM `users` WHERE `email` = :email LIMIT 1"); $stmt->execute(array(':email' => $googleUser['email'])); $user = $stmt->fetch();
<?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); }
public function test_goog() { $accessToken = '{"access_token":"ya29.AHES6ZQ9yjVf6xdFjpiLZsfqQIAxDOkm95MMv33GHySZlYNRpsgPrA","token_type":"Bearer","expires_in":3600,"refresh_token":"1\\/-qDO6Ug3qj_xnlCqMdhJ0N0zD8QxpZFBI5tFhJtOark","created":1342628689}'; App::import("Vendor", "GoogleApiClient", array("file" => "google-api-php-client/src/apiClient.php")); App::import("Vendor", "GoogleBigqueryApi", array("file" => "google-api-php-client/src/contrib/apiBigqueryService.php")); $apiClient = new apiClient(); $apiClient->setApplicationName("Testing App"); $apiClient->setClientId("*****@*****.**"); $apiClient->setClientSecret("dhWNmyamq9LPLfMpWStQbmww"); $apiClient->setRedirectUri("http://" . $_SERVER['HTTP_HOST'] . "/tester/goog_callback"); $apiClient->setScopes(array('https://www.googleapis.com/auth/bigquery')); $apiClient->setApprovalPrompt("auto"); $apiClient->setAccessToken($accessToken); $bq = new apiBigqueryService($apiClient); die(pr($bq->jobs->getQueryResults("theberrics.com:site-reports", "job_d6238b593ead456f9c8cffa0c1ea2e56"))); die(pr($bq->jobs->get("theberrics.com:site-reports", "job_d6238b593ead456f9c8cffa0c1ea2e56"))); }