public function index() { $this->id = "content"; $this->template = "login/login.tpl"; $this->layout = "common/layout-empty"; if (Registry::get('username')) { header("Location: search.php"); exit; } $request = Registry::get('request'); $session = Registry::get('session'); $db = Registry::get('db'); $this->load->model('user/auth'); $this->load->model('user/user'); $this->load->model('user/prefs'); $this->load->model('domain/domain'); $this->load->model('folder/folder'); if (ENABLE_SAAS == 1) { $this->load->model('saas/ldap'); $this->load->model('saas/customer'); } $this->data['title'] = $this->data['text_login']; $this->data['title_prefix'] = TITLE_PREFIX; $this->data['failed_login_count'] = $this->model_user_auth->get_failed_login_count(); if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate() == true) { if ($this->model_user_auth->checkLogin($this->request->post['username'], $_POST['password']) == 1) { if ($session->get("ga_block") == 1) { header("Location: " . SITE_URL . "index.php?route=login/ga"); exit; } else { $this->model_user_prefs->get_user_preferences($session->get('username')); if (ENABLE_SAAS == 1) { $this->model_saas_customer->online($session->get('email')); } LOGGER('logged in'); if (isAdminUser() == 1) { header("Location: " . SITE_URL . "index.php?route=health/health"); exit; } header("Location: " . SITE_URL . "search.php"); exit; } } else { $this->model_user_auth->increment_failed_login_count($this->data['failed_login_count']); $this->data['failed_login_count']++; } $this->data['x'] = $this->data['text_invalid_email_or_password']; } if (ENABLE_GOOGLE_LOGIN == 1) { $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); $this->data['auth_url'] = $client->createAuthUrl(); } $this->render(); }
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()); }
/** * 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); }
private function getGoogleClient($config) { require_once LIBS_DIR . '/google-api-php-client/src/apiClient.php'; require_once LIBS_DIR . '/google-api-php-client/src/contrib/apiOauth2Service.php'; $client = new apiClient(); $client->setApplicationName($config['application_name']); $client->setClientId($config['client_id']); $client->setClientSecret($config['client_secret']); $client->setRedirectUri($config['redirect_url']); $client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email')); return $client; }
/** * connect */ protected function connect() { $client = new apiClient(); $client->setApplicationName("Google Application"); //*********** Replace with Your API Credentials ************** $client->setClientId($this->clientId); $client->setClientSecret($this->clientSecret); $client->setRedirectUri($this->redirectUri); // $client->setDeveloperKey('AIzaSyBiUF9NmJKGwbJCDOQIoF2NxMgtYjwI1c8'); //************************************************************ $client->setScopes(array('https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email')); return $client; }
/** * @return apiClient */ private function createClient() { require_once 'apiClient.php'; $client = new apiClient(); /*$client->setClientId($this->getClientID()); $client->setClientSecret($this->getClientSecret()); $client->setRedirectUri($this->getRedirectUri()); $client->setDeveloperKey($this->getDeveloperKey()); $client->setApplicationName(yii::app()->name);*/ $client->setClientId(Yii::app()->functions->getOptionAdmin("google_client_id")); $client->setClientSecret(Yii::app()->functions->getOptionAdmin("google_client_secret")); $client->setRedirectUri(Yii::app()->functions->getOptionAdmin("google_client_redirect_ulr")); $client->setDeveloperKey($this->getDeveloperKey()); $client->setApplicationName(yii::app()->name); return $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 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 ''; }
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)); }
<?php require_once 'config.php'; require_once 'src/apiClient.php'; require_once 'src/contrib/apiPlusService.php'; require_once 'src/gMaps.php'; $mysqli = new mysqli(SERVER, USER, PASSWORD, DATABASE); $gmap = new gMaps(MAP_KEY); $client = new apiClient(); $plus = new apiPlusService($client); session_start(); $client->setApplicationName('Globe +'); $client->setClientId(PLUS_CLIENT_ID); $client->setClientSecret(PLUS_CLIENT_SECRET); $client->setRedirectUri(PLUS_REDIRECT_URI); $client->setDeveloperKey(PLUS_DEVELOPPER_KEY); if (isset($_GET['code'])) { $client->authenticate(); $_SESSION['access_token'] = $client->getAccessToken(); header('Location: ' . URL . $_SERVER['PHP_SELF']); } if (isset($_GET['error'])) { header('Location: ' . URL . '?status=error'); die; } if (isset($_SESSION['access_token'])) { $client->setAccessToken($_SESSION['access_token']); } if ($client->getAccessToken()) { $me = $plus->people->get('me'); // These fields are currently filtered through the PHP sanitize filters.
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) { } }
exit; } $cookie = explode('+', $_COOKIE['hexauser']); if (empty($cookie) || count($cookie) < 2) { setcookie('hexauser', '', time() - 60 * 60 * 24 * 365, '/', $_SERVER['HTTP_HOST']); echo json_encode(array('status' => 'error', 'message' => 'incomplete session')); exit; } $userId = $cookie[0]; $sessionId = $cookie[1]; require_once '../libs/google/apiClient.php'; //require_once '../libs/google/contrib/apiOauth2Service.php'; $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); $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);
<?php require_once 'src/apiClient.php'; require_once 'src/contrib/apiAnalyticsService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Google Analytics PHP Starter Application"); // Visit https://code.google.com/apis/console?api=analytics to generate your // client id, client secret, and to register your redirect uri. $client->setClientId('843646812573.apps.googleusercontent.com'); $client->setClientSecret('b3pfw2eDDACQhUnGoNsseWqe'); $client->setRedirectUri('http://brokerarena.com/ga/simple.php'); $client->setDeveloperKey('AIzaSyCU2h9wKWcRkmXxgrDxBUcEkX6sDIPn7l4'); $service = new apiAnalyticsService($client); 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']); } if ($client->getAccessToken()) { $props = $service->management_webproperties->listManagementWebproperties("~all"); print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>"; $accounts = $service->management_accounts->listManagementAccounts(); print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>"; $segments = $service->management_segments->listManagementSegments();
<?php if (!defined('NEW_GOOGLE_LOGIN')) { return; } require_once dirname(__FILE__) . '/apiClient.php'; require_once dirname(__FILE__) . '/contrib/apiOauth2Service.php'; $settings = maybe_unserialize(get_option('nextend_google_connect')); $client = new apiClient(); $client->setClientId($settings['google_client_id']); $client->setClientSecret($settings['google_client_secret']); $client->setDeveloperKey($settings['google_api_key']); $client->setRedirectUri(new_google_login_url()); $client->setApprovalPrompt('auto'); $oauth2 = new apiOauth2Service($client);
public function test_service() { App::import("Vendor", "GoogleApiClient", array("file" => "google-api-php-client/src/apiClient.php")); App::import("Vendor", "GoogleApiClient", 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->authenticate(); }
* 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. */ if (ini_get('register_globals') === "1") { die("register_globals must be turned off before using the starter application"); } require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Get Friends Id"); $client->setClientId('1057327068472.apps.googleusercontent.com'); $client->setClientSecret('EOO__L0l3dn2i97W1OHN8KT8'); $client->setRedirectUri('http://localhost/googleplus/initialize.php'); $client->setDeveloperKey('AIzaSyCoR7Exd0QXZsvE8q5CaLGtVnAM3RPGeQY'); $client->setScopes(array('https://www.googleapis.com/auth/plus.me', 'https://www.google.com/m8/feeds/')); $plus = new apiPlusService($client); 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']);
<?php require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Google+ PHP Starter Application"); //*********** Replace with Your API Credentials ************** $client->setClientId('272754976297-dakklcmbcemi2lojd383jt78nca9p0ad.apps.googleusercontent.com'); $client->setClientSecret('bIWo2hqsj1z3HT7u9p5rlsns'); $client->setRedirectUri('http://demo.webtutplus.com/google_login'); $client->setDeveloperKey('AIzaSyCa9jeGbICutfVxBgrO2aKUs9xqZTrUCF8'); //************************************************************ $client->setScopes(array('https://www.googleapis.com/auth/plus.me')); $plus = new apiPlusService($client); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } 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'])) { $client->setAccessToken($_SESSION['access_token']); } if ($client->getAccessToken()) { $me = $plus->people->get('me'); $optParams = array('maxResults' => 100); $activities = $plus->activities->listActivities('me', 'public', $optParams); $_SESSION['access_token'] = $client->getAccessToken();
* 저작권 안내 * - 저작권자는 이 프로그램을 사용하므로서 발생하는 모든 문제에 대하여 책임을 지지 않습니다. * - 이 프로그램을 어떠한 형태로든 재배포 및 공개하는 것을 허락하지 않습니다. * - 이 저작권 표시사항을 저작권자를 제외한 그 누구도 수정할 수 없습니다. */ include_once "_common.php"; include_once "{$g4['path']}/plugin/social-login/_lib.php"; include_once "{$g4['path']}/plugin/social-login/_config.php"; include_once "lib/google/apiClient.php"; include_once "lib/google/contrib/apiOauth2Service.php"; $client = new apiClient(); $client->setApplicationName("Miwit.com Social-login Solution"); // Visit https://code.google.com/apis/console?api=plus to generate your // oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri. $client->setClientId($mw_google_config[client_id]); $client->setClientSecret($mw_google_config[client_secret]); $client->setRedirectUri(set_http($mw_google_config[client_domain] . $_SERVER[SCRIPT_NAME])); //$client->setDeveloperKey('insert_your_developer_key'); $oauth2 = new apiOauth2Service($client); if (isset($_GET['code'])) { $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL)); } if (isset($_SESSION['token'])) { $client->setAccessToken($_SESSION['token']); } if (isset($_REQUEST['logout'])) { unset($_SESSION['token']); $client->revokeToken();
<?php session_start(); require_once 'includes/google-api-php-client/src/apiClient.php'; require_once 'includes/google-api-php-client/src/contrib/apiAnalyticsService.php'; $scriptUri = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER['PHP_SELF']; $client = new apiClient(); $client->setAccessType('online'); // default: offline $client->setApplicationName('odwlbs analytics'); $client->setClientId('701410038147.apps.googleusercontent.com'); $client->setClientSecret('zFG4ibjDTzl-zl8JIi9PATsH'); $client->setRedirectUri($scriptUri); $client->setDeveloperKey('AIzaSyCuAMq5usFdhFShNb5HKdPVdtrlal9m2lw'); // API key // $service implements the client interface, has to be set before auth call $service = new apiAnalyticsService($client); if (isset($_GET['logout'])) { // logout: destroy token unset($_SESSION['token']); die('Logged out.'); } if (isset($_GET['code'])) { // we received the positive auth callback, get the token and store it in session $client->authenticate(); $_SESSION['token'] = $client->getAccessToken(); } if (isset($_SESSION['token'])) { // extract token from session and configure client $token = $_SESSION['token']; $client->setAccessToken($token);
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')); } }
* 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. */ session_start(); 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();
/** * 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; }
* 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 "config.php"; $user_ip = $_SERVER["REMOTE_ADDR"]; if (!$user_ip || $user_ip == "") { $user_ip = $_SERVER["SERVER_ADDR"]; } require_once $gapi_client_path . "apiClient.php"; require_once $gapi_client_path . "contrib/apiPlusService.php"; session_start(); $client = new apiClient(); $client->setApplicationName("ProfileRoom+"); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($base_url . "index.php"); $client->setDeveloperKey($developer_key); $client->setScopes(array("https://www.googleapis.com/auth/plus.me")); $plus = new apiPlusService($client); if (isset($_GET["code"])) { $client->authenticate(); $_SESSION["access_token"] = $client->getAccessToken(); header("Location: " . $base_url . "check.php"); } if (isset($_GET["error"])) { unset($_SESSION["access_token"]); header("Location: " . $base_url); } if (isset($_REQUEST["logout"])) { unset($_SESSION["access_token"]);
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; }
* 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. */ require_once '../server.php'; require_once '../../key.php'; 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{
<p><strong>Step 4</strong>-Click on Create new Browser Key in order to set up the API Key</p> [caption id="attachment_547" align="aligncenter" width="1024"]<img src="http://webtutplus.com/wp-content/uploads/2015/07/Screenshot-1061-1024x398.png" alt="Get The API key from here" width="1024" height="398" class="size-large wp-image-547" /> Get The API key from here[/caption] <p> </p> <p><strong>Step 5</strong>-<span>Now you have to set </span><strong>Consent screen</strong><span>. This will be the screen that will be displayed before the user is redirected</span></p> [caption id="attachment_548" align="aligncenter" width="1024"]<img src="http://webtutplus.com/wp-content/uploads/2015/07/Screenshot-1072-1024x494.png" alt="The Consent Screen" width="1024" height="494" class="size-large wp-image-548" /> The Consent Screen[/caption] <p> </p> <p>Once this is done you are ready to code. Given below are the two php file codes you need to type in. You need to code using API</p><p><span style="text-decoration: underline; color: #ff0000;"><strong>google-plus-access.php</strong></span></p> <pre class="prettyprint lang-php "><?php require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Google+ PHP Starter Application"); //*********** Replace with Your API Credentials ************** $client->setClientId('621798410973-jjpnovbshh910o0nba3rbsb3il7o2qrb.apps.googleusercontent.com'); $client->setClientSecret('Y-9CFVCpPvdSd7ut_UrtOz0f'); $client->setRedirectUri('http://localhost/webtuts/google_login/'); $client->setDeveloperKey('AIzaSyBB6QfvkHGd8S1gy16GtQa7u21EAQ9gQaE'); //************************************************************ $client->setScopes(array('https://www.googleapis.com/auth/plus.me')); $plus = new apiPlusService($client); if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); } 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'])) { $client->setAccessToken($_SESSION['access_token']);
* 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. */ if (ini_get('register_globals') === "1") { die("register_globals must be turned off before using the starter application"); } require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Google+ PHP Starter Application"); $client->setClientId('583952610464-skm0ipo4hms1qleut4jinp106fnf0daf.apps.googleusercontent.com'); $client->setClientSecret('FijubFKkMgXvH-UQV4SfEypV'); $client->setRedirectUri('http://localhost/googleplus/index.php'); $client->setDeveloperKey('AIzaSyDidZKyQlgizNL3lgPRHDyucL5sOxqGqXg'); $client->setScopes(array('https://www.googleapis.com/auth/plus.me', 'https://picasaweb.google.com/data/')); $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']);
<?php require_once 'google-api-php-client/src/apiClient.php'; require_once 'google-api-php-client/src/contrib/apiPlusService.php'; session_start(); $client = new apiClient(); $client->setApplicationName("Google+ PHP Starter Application"); //*********** Replace with Your API Credentials ************** $client->setClientId('312021842419-ad2m0g33mbe862eapkl19qpbnd5mfhag.apps.googleusercontent.com'); $client->setClientSecret('9efxIU0KSGb6m2QTqcUew0eG'); $client->setRedirectUri('http://localhost/samples/php/social/google/googleplus-source/'); $client->setDeveloperKey('AIzaSyC8Y8HuCv44VAbUO8uvlDhK_NobMS7bwdo'); //************************************************************ $client->setScopes(array('https://www.googleapis.com/auth/plus.me')); $plus = new apiPlusService($client); echo '<pre>'; print_r($_SESSION); echo '</pre>'; if (isset($_REQUEST['logout'])) { unset($_SESSION['access_token']); setcookie('token', "", time() - 3600); } 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'])) { $client->setAccessToken($_SESSION['access_token']); //json decode the session token and save it in a variable as object $sessionToken = json_decode($_SESSION['access_token']);