/** * @param Entity\CloudCredentials $entity * @param Entity\CloudCredentials $prevConfig * * @throws ApiErrorException */ public function validateEntity($entity, $prevConfig = null) { parent::validateEntity($entity, $prevConfig); $ccProps = $entity->properties; $prevCcProps = isset($prevConfig) ? $prevConfig->properties : null; if ($this->needValidation($ccProps, $prevCcProps)) { $ccProps[Entity\CloudCredentialsProperty::GCE_ACCESS_TOKEN] = ""; try { $client = new \Google_Client(); $client->setApplicationName("Scalr GCE"); $client->setScopes(['https://www.googleapis.com/auth/compute']); $key = base64_decode($ccProps[Entity\CloudCredentialsProperty::GCE_KEY]); // If it's not a json key we need to convert PKCS12 to PEM if (!$ccProps[Entity\CloudCredentialsProperty::GCE_JSON_KEY]) { @openssl_pkcs12_read($key, $certs, 'notasecret'); $key = $certs['pkey']; } $client->setAuthConfig(['type' => 'service_account', 'project_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID], 'private_key' => $key, 'client_email' => $ccProps[Entity\CloudCredentialsProperty::GCE_SERVICE_ACCOUNT_NAME], 'client_id' => $ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]]); $client->setClientId($ccProps[Entity\CloudCredentialsProperty::GCE_CLIENT_ID]); $gce = new \Google_Service_Compute($client); $gce->zones->listZones($ccProps[Entity\CloudCredentialsProperty::GCE_PROJECT_ID]); } catch (Exception $e) { throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Provided GCE credentials are incorrect: ({$e->getMessage()})"); } $entity->status = Entity\CloudCredentials::STATUS_ENABLED; } }
public function googleCallbackAction() { $response = array("status" => 0, "message" => "Thao tác không thành công"); $code = $this->request->getPost("code", null, false); if ($code) { $google = new \Google_Client(); $google->setApplicationName($this->config["GOOGLE_NAME"]); $google->setClientId($this->config["GOOGLE_ID"]); $google->setClientSecret($this->config["GOOGLE_SECRET"]); $google->setRedirectUri('postmessage'); $scopes = array("https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/userinfo.email"); $google->setScopes($scopes); $google->authenticate($code); $request = new \Google_Http_Request("https://www.googleapis.com/oauth2/v2/userinfo?alt=json"); $userinfo = $google->getAuth()->authenticatedRequest($request); $response = $userinfo->getResponseBody(); $userinfo = json_decode($response, true); $id = $userinfo["id"]; $username = explode("@", $userinfo["email"]); $username = $username[0] . "_gg_" . $id; $data_user = array("email" => $userinfo["email"], "nickname" => $userinfo["name"], "username" => $username, "id" => $id); $response = $this->doSocialLogin($data_user); } echo json_encode($response); exit; }
public function signin() { $client = new \Google_Client(); $client->setClientId(Config::get('ntentan:social.google.client_id')); $client->setClientSecret(Config::get('ntentan:social.google.client_secret')); $client->setRedirectUri(Config::get('ntentan:social.google.redirect_uri')); $client->addScope(array('profile', 'email')); $oauth2 = new \Google_Service_Oauth2($client); if (isset($_REQUEST['logout'])) { Session::set('access_token', ''); $client->revokeToken(); } if (isset($_GET['code'])) { $client->authenticate($_GET['code']); Session::set('access_token', $client->getAccessToken()); Redirect::path(\ntentan\Router::getRoute()); } if (isset($_SESSION['access_token'])) { $client->setAccessToken($_SESSION['access_token']); } if ($client->isAccessTokenExpired()) { $authUrl = $client->createAuthUrl(); header('Location: ' . filter_var($authUrl, FILTER_SANITIZE_URL)); } if ($client->getAccessToken()) { $user = $oauth2->userinfo->get(); $_SESSION['token'] = $client->getAccessToken(); return array('firstname' => $user['given_name'], 'lastname' => $user['family_name'], 'key' => "google_{$user['id']}", 'avatar' => $user['picture'], 'email' => $user['email'], 'email_confirmed' => $user['verified_email']); } else { header("Location: {$client->createAuthUrl()}"); die; } return false; }
public function testSettersGetters() { $client = new Google_Client(); $client->setClientId("client1"); $client->setClientSecret('client1secret'); $client->setState('1'); $client->setApprovalPrompt('force'); $client->setAccessType('offline'); $client->setRedirectUri('localhost'); $client->setApplicationName('me'); $this->assertEquals('object', gettype($client->getAuth())); $this->assertEquals('object', gettype($client->getCache())); $this->assertEquals('object', gettype($client->getIo())); $client->setAuth(new Google_Auth_Simple($client)); $client->setAuth(new Google_Auth_OAuth2($client)); try { $client->setAccessToken(null); die('Should have thrown an Google_Auth_Exception.'); } catch (Google_Auth_Exception $e) { $this->assertEquals('Could not json decode the token', $e->getMessage()); } $token = json_encode(array('access_token' => 'token')); $client->setAccessToken($token); $this->assertEquals($token, $client->getAccessToken()); }
public function __construct($oauthClientId, $oauthClientSecret, $oAuthConfig = array()) { $this->client = new \Google_Client(); $this->client->setClassConfig('Google_Auth_OAuth2', $oAuthConfig); $this->client->setClientId($oauthClientId); $this->client->setClientSecret($oauthClientSecret); }
public function __construct() { include_once AB_PATH . '/lib/google_api_v3/autoload.php'; $this->client = new Google_Client(); $this->client->setClientId(get_option('ab_settings_google_client_id')); $this->client->setClientSecret(get_option('ab_settings_google_client_secret')); }
/** * Google constructor. */ public function __construct() { $this->_googleClient = new \Google_Client(); $this->_googleClient->setClientId(KACANA_SOCIAL_GOOGLE_KEY); $this->_googleClient->setClientSecret(KACANA_SOCIAL_GOOGLE_SECRET); $this->_googleClient->setApplicationName(KACANA_SOCIAL_GOOGLE_APP_NAME); $this->_googleClient->setRedirectUri('postmessage'); }
/** * @param \Google_Client $client */ public function __construct(\Google_Client $client) { $this->client = $client; $this->client->setClientId(\Config::get('google.client_id')); $this->client->setClientSecret(\Config::get('google.client_secret')); $this->client->setDeveloperKey(\Config::get('google.api_key')); $this->client->setRedirectUri(\Config::get('app.url') . "/loginCallback"); $this->client->setScopes(['https://www.googleapis.com/auth/youtube']); $this->client->setAccessType('offline'); }
/** * Google * @param $params array - data from config.neon * @param $cookieName String cookie name * @param Nette\Http\Response $httpResponse * @param Nette\Http\Request $httpRequest */ public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest) { $this->params = $params; $this->cookieName = $cookieName; $this->httpResponse = $httpResponse; $this->httpRequest = $httpRequest; $this->client = new \Google_Client(); $this->client->setClientId($this->params["clientId"]); $this->client->setClientSecret($this->params["clientSecret"]); $this->client->setRedirectUri($this->params["callbackURL"]); }
/** * Constructor. * * @param int $repositoryid repository instance id. * @param int|stdClass $context a context id or context object. * @param array $options repository options. * @param int $readonly indicate this repo is readonly or not. * @return void */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0) { parent::__construct($repositoryid, $context, $options, $readonly = 0); $callbackurl = new moodle_url(self::CALLBACKURL); $this->client = get_google_client(); $this->client->setClientId(get_config('googledocs', 'clientid')); $this->client->setClientSecret(get_config('googledocs', 'secret')); $this->client->setScopes(array(Google_Service_Drive::DRIVE_READONLY)); $this->client->setRedirectUri($callbackurl->out(false)); $this->service = new Google_Service_Drive($this->client); $this->check_login(); }
/** * Constructor. * * @param int $repositoryid repository instance id. * @param int|stdClass $context a context id or context object. * @param array $options repository options. * @param int $readonly indicate this repo is readonly or not. * @return void */ public function __construct($repositoryid, $context = SYSCONTEXTID, $options = array(), $readonly = 0) { parent::__construct($repositoryid, $context, $options, $readonly = 0); $callbackurl = new moodle_url(self::CALLBACKURL); $this->client = new Google_Client(); $this->client->setClientId(get_config('googledocs', 'clientid')); $this->client->setClientSecret(get_config('googledocs', 'secret')); $this->client->setScopes(array('https://www.googleapis.com/auth/drive.readonly')); $this->client->setRedirectUri($callbackurl->out(false)); $this->service = new Google_DriveService($this->client); $this->check_login(); }
/** * Google * @param $params array - data from config.neon * @param $cookieName String cookie name * @param Nette\Http\Response $httpResponse * @param Nette\Http\Request $httpRequest */ public function __construct($params, $cookieName, Nette\Http\Response $httpResponse, Nette\Http\Request $httpRequest) { $this->params = $params; $this->cookieName = $cookieName; $this->httpResponse = $httpResponse; $this->httpRequest = $httpRequest; $config = new \Google_Config(); $config->setClassConfig('Google_Cache_File', array('directory' => '/temp/cache')); $this->client = new \Google_Client($config); $this->client->setClientId($this->params["clientId"]); $this->client->setClientSecret($this->params["clientSecret"]); $this->client->setRedirectUri($this->params["callbackURL"]); }
public function initializeClient() { $this->client = new Client(); $this->client->setAccessType('offline'); $this->client->setApplicationName('playlister'); $this->client->setClientId($this->config->get('services.youtube.client_id')); $this->client->setClientSecret($this->config->get('services.youtube.client_secret')); $this->client->setRedirectUri($this->config->get('services.youtube.redirect')); $this->client->setDeveloperKey($this->config->get('services.youtube.api_key')); $this->client->addScope('https://www.googleapis.com/auth/youtube.readonly'); if ($this->auth->check() && $this->request->session()->has('user.token')) { $this->setToken($this->request->session()->get('user.token')); } }
/** * @return object | $service | Google Analytics Service Object used to run queries **/ private function createAnalyticsService() { /** * Create and Authenticate Google Analytics Service Object **/ $client = new Google_Client(); $client->setApplicationName(GOOGLE_API_APP_NAME); /** * Makes sure Private Key File exists and is readable. If you get an error, check path in apiConfig.php **/ if (!file_exists(GOOGLE_API_PRIVATE_KEY_FILE)) { array_push($GLOBALS['criticalErrors'], "CRITICAL-ERROR: Unable to find GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE); criticalErrorOccurred($criticalErrors, $errors); exit("CRITICAL-ERROR: Unable to find GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE . ' Backup aborted.'); } elseif (!is_readable(GOOGLE_API_PRIVATE_KEY_FILE)) { array_push($GLOBALS['criticalErrors'], "CRITICAL-ERROR: Unable to read GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE); criticalErrorOccurred($criticalErrors, $errors); exit("CRITICAL-ERROR: Unable to read GOOGLE_API_PRIVATE_KEY_FILE p12 file at " . GOOGLE_API_PRIVATE_KEY_FILE . ' Backup aborted.'); } $client->setAssertionCredentials(new Google_AssertionCredentials(GOOGLE_API_SERVICE_EMAIL, array('https://www.googleapis.com/auth/analytics.readonly'), file_get_contents(GOOGLE_API_PRIVATE_KEY_FILE))); $client->setClientId(GOOGLE_API_SERVICE_CLIENT_ID); $client->setUseObjects(true); $service = new Google_AnalyticsService($client); return $service; }
private function createClient() { $options = ['auth' => 'google_auth', 'exceptions' => false]; if ($proxy = getenv('HTTP_PROXY')) { $options['proxy'] = $proxy; $options['verify'] = false; } // adjust constructor depending on guzzle version if (!$this->isGuzzle6()) { $options = ['defaults' => $options]; } $httpClient = new GuzzleHttp\Client($options); $client = new Google_Client(); $client->setApplicationName('google-api-php-client-tests'); $client->setHttpClient($httpClient); $client->setScopes(["https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/tasks", "https://www.googleapis.com/auth/adsense", "https://www.googleapis.com/auth/youtube", "https://www.googleapis.com/auth/drive"]); if ($this->key) { $client->setDeveloperKey($this->key); } list($clientId, $clientSecret) = $this->getClientIdAndSecret(); $client->setClientId($clientId); $client->setClientSecret($clientSecret); $client->setCache($this->getCache()); return $client; }
public function googlecallback() { $ret = null; //$google_redirect_url = site_url('user/signup'); $google_redirect_url = 'http://localhost/punu/punu/index.php/user/signup'; $client = new Google_Client(); $client->setClientId($this->google_client_id); $client->setClientSecret($this->google_client_secret); $client->setDeveloperKey($this->google_api_key); $client->setRedirectUri($google_redirect_url); $client->addScope($this->google_scope); // Send Client Request $objOAuthService = new Google_Service_Oauth2($client); // Add Access Token to Session if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $_SESSION['google_access_token'] = $client->getAccessToken(); //header('Location: ' . filter_var($this->google_redirect_url, FILTER_SANITIZE_URL)); } // Set Access Token to make Request if (isset($_SESSION['google_access_token']) && $_SESSION['google_access_token']) { $client->setAccessToken($_SESSION['google_access_token']); } // Get User Data from Google and store them in $data if ($client->getAccessToken()) { $userData = $objOAuthService->userinfo->get(); //$_SESSION['userData'] = $userData; $_SESSION['google_access_token'] = $client->getAccessToken(); $ret = $userData; } return $ret; }
public function index() { //Config items added to global config file $clientId = $this->config->item('clientId'); $clientSecret = $this->config->item('clientSecret'); $redirectUrl = $this->config->item('redirectUrl'); #session_start(); $client = new Google_Client(); $client->setClientId($clientId); $client->setClientSecret($clientSecret); $client->setRedirectUri($redirectUrl); #$client->setScopes(array('https://spreadsheets.google.com/feeds')); $client->addScope(array('https://spreadsheets.google.com/feeds')); $client->addScope('email'); $client->addScope('profile'); $client->setApprovalPrompt('force'); //Useful if you had already granted access to this application. $client->setAccessType('offline'); //Needed to get a refresh_token $data['base_url'] = $this->config->item('base_url'); $data['auth_url'] = $client->createAuthUrl(); //Set canonical URL $data['canonical'] = $this->config->item('base_url') . 'docs'; $this->load->view('docs', $data); }
function onNextendYoutube(&$google, &$youtube) { $config = new NextendData(); $config->loadJson(NextendSmartSliderStorage::get(self::$_group)); if (!class_exists('Google_Client')) { require_once dirname(__FILE__) . '/googleclient/Google_Client.php'; } if (!class_exists('Google_YouTubeService')) { require_once dirname(__FILE__) . '/googleclient/contrib/Google_YouTubeService.php'; } $google = new Google_Client(); $google->setClientId($config->get('apikey', '')); $google->setClientSecret($config->get('apisecret', '')); $token = $config->get('token', null); if ($token) { $google->setAccessToken($token); } $youtube = new Google_YouTubeService($google); if ($google->isAccessTokenExpired()) { $token = json_decode($google->getAccessToken(), true); if (isset($token['refresh_token'])) { $google->refreshToken($token['refresh_token']); $config->set('token', $google->getAccessToken()); NextendSmartSliderStorage::set(self::$_group, $config->toJSON()); } } }
public function call_back() { $config = new Controllers_Api_Google_Config_App(); $client = new Google_Client(); $client->setClientId($config->config['client_id']); $client->setClientSecret($config->config['client_secret']); $client->setRedirectUri($config->config['redirect_uri']); $client->addScope("email"); $client->addScope("profile"); $service = new Google_Service_Oauth2($client); if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $_SESSION['access_token'] = $client->getAccessToken(); header('Location: ' . filter_var($config->config['redirect_uri'], FILTER_SANITIZE_URL)); exit; } /************************************************ If we have an access token, we can make requests, else we generate an authentication URL. ************************************************/ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } else { $authUrl = $client->createAuthUrl(); } if (isset($authUrl)) { //show login url echo json_encode(array('status' => false, 'data' => $authUrl)); } else { $user = $service->userinfo->get(); //get user info echo json_encode(array('status' => true, 'data' => $user)); } }
public static function revokeAccessToken() { $xmpData = erLhcoreClassModelChatConfig::fetch('xmp_data'); $data = (array) $xmpData->data; try { if (isset($data['gtalk_client_token']) && $data['gtalk_client_token'] != '') { require_once 'lib/core/lhxmp/google/Google_Client.php'; $client = new Google_Client(); $client->setApplicationName('Live Helper Chat'); $client->setScopes(array("https://www.googleapis.com/auth/googletalk", "https://www.googleapis.com/auth/userinfo.email")); $client->setClientId($data['gtalk_client_id']); $client->setClientSecret($data['gtalk_client_secret']); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $token = $data['gtalk_client_token']; $client->setAccessToken($data['gtalk_client_token']); // Refresh token if it's if ($client->isAccessTokenExpired()) { $tokenData = json_decode($token); $client->refreshToken($tokenData->refresh_token); $accessToken = $client->getAccessToken(); } if ($accessToken = $client->getAccessToken()) { $client->revokeToken(); } unset($data['gtalk_client_token']); $xmpData->value = serialize($data); $xmpData->saveThis(); } return true; } catch (Exception $e) { throw $e; } }
public function __construct() { $google = new \Google_Client(); $google->setClientId(Setting::get('google.clientId')); $google->setClientSecret(Setting::get('google.clientSecret')); $this->google = $google; }
function authorizeGoogleUser($access_code) { $client = new \Google_Client(); $google = $this->config->google; $client->setApplicationName('Portal da Rede'); $client->setClientId($google->clientId); $client->setClientSecret($google->secret); $client->setRedirectUri('postmessage'); $client->addScope('https://www.googleapis.com/auth/userinfo.profile'); $client->addScope('https://www.googleapis.com/auth/userinfo.email'); $client->authenticate($access_code); $json_token = $client->getAccessToken(); $client->setAccessToken($json_token); $plus = new \Google_Service_Plus($client); $user = $plus->people->get('me'); if (!$user->emails || !is_array($user->emails)) { return; } $email = $user->emails[0]['value']; $user_email = $this->db->user_email->find_one($email); if (!$user_email) { return; } $this->login($user_email->user); }
/** * Initializes the Google Drive connection * * @param array $params Any connection params needed * @return object **/ public static function init($params = []) { // Get the params $pparams = Plugin::params('filesystem', 'googledrive'); $app_id = isset($params['app_id']) && $params['app_id'] != '' ? $params['app_id'] : $pparams->get('app_id'); $app_secret = isset($params['app_secret']) && $params['app_secret'] != '' ? $params['app_secret'] : $pparams->get('app_secret'); $client = new \Google_Client(); $client->setClientId($app_id); $client->setClientSecret($app_secret); $client->addScope(Google_Service_Drive::DRIVE); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $client->setIncludeGrantedScopes(true); if (isset($params['app_token'])) { $accessToken = $params['app_token']; // json encode turned our array into an object, we need to undo that $accessToken = (array) $accessToken; } else { \Session::set('googledrive.app_id', $app_id); \Session::set('googledrive.app_secret', $app_secret); \Session::set('googledrive.connection_to_set_up', Request::getVar('connection', 0)); // Set upp a return and redirect to Google for auth $return = Request::getVar('return') ? Request::getVar('return') : Request::current(true); $return = base64_encode($return); $redirectUri = trim(Request::root(), '/') . '/developer/callback/googledriveAuthorize'; $client->setRedirectUri($redirectUri); Session::set('googledrive.state', $return); App::redirect($client->createAuthUrl()); } $client->setAccessToken($accessToken); $service = new \Google_Service_Drive($client); $adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, 'root'); return $adapter; }
/** * Login to facebook and get the associated cloudrexx user. */ public function login() { $client = new \Google_Client(); $client->setApplicationName('Contrexx Login'); $client->setClientId($this->applicationData[0]); $client->setClientSecret($this->applicationData[1]); $client->setRedirectUri(\Cx\Lib\SocialLogin::getLoginUrl(self::OAUTH_PROVIDER)); $client->setDeveloperKey($this->applicationData[2]); $client->setUseObjects(true); $client->setApprovalPrompt('auto'); $client->setScopes(self::$scopes); self::$google = new \Google_Oauth2Service($client); self::$googleplus = new \Google_PlusService($client); if (isset($_GET['code'])) { try { $client->authenticate(); } catch (\Google_AuthException $e) { } } if (!$client->getAccessToken()) { \Cx\Core\Csrf\Controller\Csrf::header('Location: ' . $client->createAuthUrl()); exit; } self::$userdata = $this->getUserData(); $this->getContrexxUser(self::$userdata['oauth_id']); }
function getClient() { $config = (include __DIR__ . '/ini.php'); $client = new Google_Client(); $client->setApplicationName("Webkameleon"); $client->setClientId($config['oauth2_client_id']); $client->setClientSecret($config['oauth2_client_secret']); $client->setRedirectUri($config['oauth2_redirect_uri']); $client->setScopes($config['oauth2_scopes']); $client->setState('offline'); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); if (isset($_GET['code'])) { $client->authenticate($_GET['code']); die($client->getAccessToken()); } elseif (!isset($config['token'])) { Header('Location: ' . $client->createAuthUrl()); } else { $client->setAccessToken($config['token']); if ($client->isAccessTokenExpired()) { $token = json_decode($config['token'], true); $client->refreshToken($token['refresh_token']); } } return $client; }
function getClient() { $client = new Google_Client(); $client->setApplicationName(getGAAppName()); $client->setClientId(getGAClientID()); return $client; }
/** * Sets the required params for authentication * * @param string $client_id our app's client id * @param string $client_secret our app's client secret * @param string $redirect_uri where will the auth server send the client * after generating an authorization code to authenticate * @param null|string $token token obtained when a code is authenticated * @param null|string $code response code to authenticate * @param null|array $scopes array of strings with OAuth2/google scopes * to requested * @param null|Google_Client $client * @param bool $debug defaults to false */ public function __construct($client_id, $client_secret, $redirect_uri, $token = null, $code = null, $scopes = null, $client = null, $debug = null) { $this->client_id = $client_id; $this->client_secret = $client_secret; $this->redirect_uri = $redirect_uri; $this->code = $code; $this->token = $token; if ($scopes !== null) { $this->scopes = $scopes; } if (is_bool($this->debug)) { $this->debug = $debug; } else { $this->debug = false; } if ($client === null) { $this->client = new Google_Client(); $this->client->setClientId($this->client_id); $this->client->setClientSecret($this->client_secret); $this->client->setRedirectUri($this->redirect_uri); if ($token !== null) { $this->client->setAccessToken($token); } $this->client->setScopes($this->scopes); } }
public function __construct($clientId, $serviceAccountName, $key) { $client = new Google_Client(); $client->setClientId($clientId); $client->setAssertionCredentials(new Google_Auth_AssertionCredentials($serviceAccountName, $this->scope, file_get_contents($key))); $this->sef = new Google_Service_Drive($client); }
function do_something_with_user($email) { global $key; $user_client = new Google_Client(); $user_client->setApplicationName("Google+ Domains API Sample"); $user_credentials = new Google_AssertionCredentials(SERVICE_ACCOUNT_EMAIL, array("https://www.googleapis.com/auth/plus.me", "https://www.googleapis.com/auth/plus.stream.read"), $key); // Set the API Client to act on behalf of the specified user $user_credentials->sub = $email; $user_client->setAssertionCredentials($user_credentials); $user_client->setClientId(CLIENT_ID); $plusService = new Google_PlusService($user_client); // Try to retrieve Google+ Profile information about the current user try { $result = $plusService->people->get("me"); } catch (Exception $e) { printf(" / Not a Google+ User<br><br>\n"); return; } printf(" / <a href=\"%s\">Google+ Profile</a>\n", $result["url"]); // Retrieve a list of Google+ activities for the current user $activities = $plusService->activities->listActivities("me", "user", array("maxResults" => 100)); if (isset($activities["items"])) { printf(" / %s activities found<br><br>\n", count($activities["items"])); } else { printf(" / No activities found<br><br>\n"); } }
function setAppConfig($approval = 'auto') { $this->client = new Google_Client(); /* Set Retries */ $this->client->setClassConfig('Google_Task_Runner', 'retries', 5); $this->userInfoService = new Google_Service_Oauth2($this->client); $this->googleDriveService = new Google_Service_Drive($this->client); $this->googleUrlshortenerService = new Google_Service_Urlshortener($this->client); if (!empty($this->settings['googledrive_app_client_id']) && !empty($this->settings['googledrive_app_client_secret'])) { $this->client->setClientId($this->settings['googledrive_app_client_id']); $this->client->setClientSecret($this->settings['googledrive_app_client_secret']); } else { $this->client->setClientId('538839470620-fvjmtsvik53h255bnu0qjmbr8kvd923i.apps.googleusercontent.com'); $this->client->setClientSecret('UZ1I3I-D4rPhXpnE8T1ggGhE'); } $this->client->setRedirectUri('http://www.florisdeleeuw.nl/use-your-drive/index.php'); $this->client->setApprovalPrompt($approval); $this->client->setAccessType('offline'); $this->client->setScopes(array('https://www.googleapis.com/auth/drive', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/urlshortener')); $page = isset($_GET["page"]) ? '?page=' . $_GET["page"] : ''; $location = get_admin_url(null, 'admin.php' . $page); $this->client->setState(strtr(base64_encode($location), '+/=', '-_~')); /* Logger */ $this->client->setClassConfig('Google_Logger_File', array('file' => USEYOURDRIVE_CACHEDIR . '/log', 'mode' => 0640, 'lock' => true)); $this->client->setClassConfig('Google_Logger_Abstract', array('level' => 'debug', 'log_format' => "[%datetime%] %level%: %message% %context%\n", 'date_format' => 'd/M/Y:H:i:s O', 'allow_newlines' => true)); /* Uncomment the following line to log communcations. * The log is located in /cache/log */ //$this->client->setLogger(new Google_Logger_File($this->client)); return true; }