public function add_google_client() { $auth_config = $this->get_auth_config(); if (!empty($auth_config)) { try { $client = new Google_Client(); $client->setAuthConfig($this->get_auth_config()); $client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); $client->setAccessType('offline'); $token = $this->get_token(); if ($token) { $client->setAccessToken($token); } if ($client->isAccessTokenExpired()) { $refresh_token = $this->get_refresh_token(); if ($refresh_token) { $client->refreshToken($refresh_token); $this->update_token($client->getAccessToken()); } } $this->client = $client; $this->service = new Google_Service_Analytics($this->client); } catch (Exception $e) { $message = 'Google Analytics Error[' . $e->getCode() . ']: ' . $e->getMessage(); $this->disconnect($message); error_log($message, E_USER_ERROR); return; } } }
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; }
/** * Google login method * -- */ public function flow() { $client = new Google_Client(); $client->setClientId($this->client_id); $client->setClientSecret($this->client_secret); $client->setRedirectUri($this->redirect_url); $client->addScope("email"); $client->addScope("profile"); $this->context = Context::getContext(); $this->client = $client; $this->service = new Google_Service_Oauth2($this->client); if (Tools::getValue('code')) { $this->client->authenticate(Tools::getValue('code')); $this->context->cookie->__set('googleconnect_access_token', serialize($this->client->getAccessToken())); Tools::redirect(filter_var($this->redirect_url, FILTER_SANITIZE_URL)); } else { if ($this->context->cookie->__isset('googleconnect_access_token')) { $a_token = unserialize($this->context->cookie->__get('googleconnect_access_token')); $this->client->setAccessToken($a_token); if (!$this->client->isAccessTokenExpired()) { $this->context->cookie->__unset('googleconnect_access_token'); $this->loginToStore(); } else { $this->setAuthUrl(); } } else { $this->setAuthUrl(); } } }
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); }
public static function getClient() { $creds = GoogleSessionController::getCreds(); $client = new Google_Client(); $env = Config::getEnvironment(); if ($env == 'local' && $creds->oauth_local_path) { $client->setAuthConfigFile($creds->oauth_local_path); } else { if ($creds->oauth_remote_path) { $client->setAuthConfigFile($creds->oauth_remote_path); } else { $client->setApplicationName($creds->app_name); $client->setClientId($creds->client_id); $client->setClientSecret($creds->client_secret); } } $client->setRedirectUri(GoogleSessionController::getRedirectURI()); $hd = Config::get('config.google.hd'); if ($hd) { $client->setHostedDomain($hd); } $client->setAccessType('offline'); $client->addScope("https://www.googleapis.com/auth/userinfo.profile"); $client->addScope("https://www.googleapis.com/auth/userinfo.email"); $client->setScopes($creds->scopes); return $client; }
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)); } }
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); }
public function __construct(\Google_Client $googleClient, $clientSecretPath) { $this->_googleClient = $googleClient; $this->_googleClient->setAuthConfigFile($clientSecretPath); $this->_googleClient->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/loginGoogle'); $this->_googleClient->addScope(\Google_Service_Gmail::GMAIL_READONLY); $this->_gmailService = new \Google_Service_Gmail($this->_googleClient); }
private function load_google_analytics() { WooCommerce_Grow::load_google_analytics(); // We setup the Google Client object $this->client = new Google_Client(); $this->client->setAuthConfigFile(WooCommerce_Grow::get_plugin_path() . '\\ga-config.json'); $this->client->addScope(Google_Service_Analytics::ANALYTICS_READONLY); $this->analytics = new Google_Service_Analytics($this->client); }
/** * GoogleServiceProvider constructor. * @param $config */ public function __construct() { $this->client = new \Google_Client(); $this->projectName = config('google_cloud_storage.application'); $this->projectBucket = config('google_cloud_storage.bucket'); $this->authJsonFile = config('google_cloud_storage.auth_json_filename'); $this->client->setApplicationName($this->projectName); $this->client->setAuthConfigFile(base_path($this->authJsonFile)); $this->client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL); }
/** * GoogleServiceProvider constructor. * @param $config */ public function __construct() { $this->client = new \Google_Client(); $this->projectName = config('google_pub_sub.application'); $this->authJsonFile = config('google_pub_sub.auth_json_filename'); $this->client->setApplicationName($this->projectName); $this->client->setAuthConfigFile(base_path($this->authJsonFile)); //THIS IS NEEDED FOR CHROME ENV //$this->client->useApplicationDefaultCredentials(); $this->client->addScope(Google_Service_Pubsub::PUBSUB); }
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')); } }
function googleConnect() { require_once 'lib/Google/autoload.php'; /* * *********************Google login************************ */ $client = new Google_Client(); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri(GOOGLE_REDIRECT_URI); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); $client->addScope("openid email"); $client->addScope("https://picasaweb.google.com/data/"); $client->addScope("https://www.googleapis.com/auth/userinfo.profile"); 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 static function getClient() { // $config = self::loadConfig(); $client = new Google_Client(); $client->setAuthConfigFile(dirname(__FILE__) . '/client_secret.json'); $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . FOLDER_APP); $client->addScope(Google_Service_Gmail::MAIL_GOOGLE_COM); $client->addScope(Google_Service_Gmail::GMAIL_COMPOSE); $client->addScope(Google_Service_Gmail::GMAIL_MODIFY); $client->addScope('http://www.google.com/m8/feeds/'); $client->addScope('https://www.googleapis.com/auth/userinfo.email'); $client->setIncludeGrantedScopes(true); $client->setAccessType('offline'); $client->setApprovalPrompt('force'); return $client; }
/** * 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; }
/** * Returns an authorized API client. * @return Google_Client the authorized client object */ function getClient() { $client = new Google_Client(); $client->setApplicationName("Study Group Finder"); $client->setAuthConfigFile(__DIR__ . '/client_secret.json'); $client->addScope(Google_Service_Calendar::CALENDAR); $client->setRedirectUri(current_url()); if (isset($_SESSION["googleauth"])) { $client->setAccessToken($_SESSION["googleauth"]); $_SESSION["googleauth"] = NULL; return $client; } if (!isset($_GET['code'])) { // Request authorization from the user. $authUrl = $client->createAuthUrl(); header("Location: {$authUrl}"); exit(0); } $authCode = $_GET['code']; // Exchange authorization code for an access token. $accessToken = $client->authenticate($authCode); $_SESSION["googleauth"] = $accessToken; header("Location: calendar.php"); exit(0); }
public function get() { $callback = 'http://api.soundeavor.com/User/Auth/Login/Google/index.php'; $config = new \Google_Config(); $config->setApplicationName('Soundeavor'); $config->setClientId(Config::getConfig('GoogleClientId')); $config->setClientSecret(Config::getConfig('GoogleClientSecret')); $config->setRedirectUri($callback); $client = new \Google_Client($config); /* * Add scopes (permissions) for the client https://developers.google.com/oauthplayground/ */ $client->addScope('https://www.googleapis.com/auth/plus.me'); if (!isset($_GET['code'])) { $loginUrl = $client->createAuthUrl(); header('Location: ' . $loginUrl); } $code = $_GET['code']; $client->authenticate($code); $accessToken = $client->getAccessToken(); $accessToken = $accessToken['access_token']; $service = new \Google_Service_Plus($client); $scopes = $service->availableScopes; print_r($scopes); die; }
function getClient() { // Authenticate your API Client $client = new Google_Client(); //$client->addScope(Google_Service_Storage::DEVSTORAGE_FULL_CONTROL); $client->addScope(Google_Service_Storage::DEVSTORAGE_READ_WRITE); // see ~/sandbox/zouk-event-calendar/vendor/google/apiclient/src/Google/Service/Storage.php $client->setAccessType("offline"); $client->useApplicationDefaultCredentials(); // no need to acquire special credentials $token = $client->getAccessToken(); if (!$token) { // this is always the case, and same access token is aquired in the fetch call below (can be printed) //syslog(LOG_DEBUG, "girish: access token not present"); $token = $client->fetchAccessTokenWithAssertion(); $client->setAccessToken($token); //syslog(LOG_DEBUG, $token['access_token']); } // token acquried above is always expired. and even if you run fetchAccess...Refreshtoken() it still stays expired //if ($client->isAccessTokenExpired()) { // //syslog(LOG_DEBUG, "girish: access token expired"); // $client->fetchAccessTokenWithRefreshToken($token); //} //if ($client->isAccessTokenExpired()) { // syslog(LOG_DEBUG, "girish: access token still expired!"); // no idea how this works //} return $client; }
function createAuthorizedClient() { $client = new Google_Client(); $client->useApplicationDefaultCredentials(); $client->addScope(Google_Service_Bigquery::BIGQUERY); $service = new Google_Service_Bigquery($client); return $service; }
public function index() { // include_once APPPATH . 'libraries/Facebook/facebook.php'; // $facebook = new Facebook([ // 'appId' => '852953064822534', // 'secret' => '29888930212d679180731cc5232732c8' // ]); // $user = $facebook->getUser(); include_once APPPATH . 'libraries/Google/autoload.php'; $client_id = GOOGLE_CLIENT_ID; $client_secret = GOOGLE_CLIENT_SECRET; $redirect_uri = GOOGLE_REDIRECT_URL; // Create Client Request to access Google API $client = new Google_Client(); $client->setApplicationName("PHP Google OAuth Login Example"); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->addScope("https://www.googleapis.com/auth/userinfo.email"); // Send Client Request $objOAuthService = new Google_Service_Oauth2($client); // Add Access Token to Session if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $this->session->set_userdata(array('access_token' => $client->getAccessToken())); // header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); } // Set Access Token to make Request if ($this->session->userdata('access_token') != null) { $client->setAccessToken($this->session->userdata('access_token')); } // Get User Data from Google and store them in $data if ($client->getAccessToken()) { $userData = $objOAuthService->userinfo->get(); $data['userData'] = $userData; $this->session->set_userdata(array('access_token' => $client->getAccessToken())); $ret = $this->User_model->addUser($data['userData']); if ($ret == 'SUSPENDED') { $unset = array('access_token'); $this->session->unset_userdata($unset); $newdata = array('error' => "<font color='red'>Your account has been suspended</font>"); $this->session->set_flashdata($newdata); redirect('signin'); } else { if ($ret == 'FAIL') { $newdata = array('error' => "<font color='red'>Something is issue with login</font>"); $this->session->set_flashdata($newdata); redirect('signin'); } } redirect('dashboard'); } else { $authUrl = $client->createAuthUrl(); $data['authUrl'] = $authUrl; // $data['fbLoginUrl'] = $fbLoginUrl; loadView('signIn', $data); } }
public function google() { $client = new \Google_Client(); $client->setClientId(\Config::get('google-id')); $client->setClientSecret(\Config::get('google-secret')); $client->setRedirectUri(\URL::route('google-auth')); $client->addScope('https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile'); return $client; }
/** * Constructor for current class * * @param string $clientId * @param string $clientSecret * @param string $refreshToken * @return GMail */ public static function createByParams($clientId, $clientSecret, $refreshToken) { $client = new \Google_Client(); $client->setClientId($clientId); $client->setClientSecret($clientSecret); $client->addScope(\Google_Service_Gmail::MAIL_GOOGLE_COM); $client->refreshToken($refreshToken); return self::createByClient($client); }
/** * @param $staff_id * @return string */ public function createAuthUrl($staff_id) { $this->client->setRedirectUri($this->generateRedirectURI()); $this->client->addScope('https://www.googleapis.com/auth/calendar'); $this->client->setState(strtr(base64_encode($staff_id), '+/=', '-_,')); $this->client->setApprovalPrompt('force'); $this->client->setAccessType('offline'); return $this->client->createAuthUrl(); }
public function index() { $this->load->helper('url'); //For load css from config file $ci =& get_instance(); $header_js = $ci->config->item('css'); // Include two files from google-php-client library in controller require_once APPPATH . "libraries/google-api-php-client-master/src/Google/autoload.php"; require_once APPPATH . "libraries/google-api-php-client-master/src/Google/Client.php"; require_once APPPATH . "libraries/google-api-php-client-master/src/Google/Service/Oauth2.php"; // Store values in variables from project created in Google Developer Console $client_id = '180391628117-hf4di0a3l0aaq10c6h933n97p4e1lb2m.apps.googleusercontent.com'; $client_secret = 'Eg_i_sihLL5E5FMGTnyKSVXK'; $redirect_uri = 'http://citest.local.com/index.php/login'; $simple_api_key = 'AIzaSyCSS5nGOzy7OcuSvSMwblVRRPZ9_TFIDnM'; // Create Client Request to access Google API $client = new Google_Client(); $client->setApplicationName("PHP Google OAuth Login Example"); $client->setClientId($client_id); $client->setClientSecret($client_secret); $client->setRedirectUri($redirect_uri); $client->setDeveloperKey($simple_api_key); $client->addScope("https://www.googleapis.com/auth/userinfo.email"); // Send Client Request $objOAuthService = new Google_Service_Oauth2($client); // Add Access Token to Session if (isset($_GET['code'])) { $client->authenticate($_GET['code']); $_SESSION['access_token'] = $client->getAccessToken(); header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); } // Set Access Token to make Request if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { $client->setAccessToken($_SESSION['access_token']); } // Get User Data from Google and store them in $data if ($client->getAccessToken()) { $userData = $objOAuthService->userinfo->get(); //Save google login user data in database $saveData = array('name' => $userData['name'], 'email' => $userData['email'], 'gender' => $userData['gender']); $this->user_model->saveUserData($saveData); $data['userData'] = $userData; $_SESSION['access_token'] = $client->getAccessToken(); } else { $authUrl = $client->createAuthUrl(); $data['authUrl'] = $authUrl; } //Load css file added in config file $str = ''; foreach ($header_js as $key => $val) { $str .= '<link rel="stylesheet" href="' . base_url() . 'css/' . $val . '" type="text/css" />' . "\n"; } $data['css'] = $str; // Load view and send values stored in $data $this->load->view('google_authentication', $data); }
public function getAuthenticationUrl() { $client = new Google_Client(); $client->setClientId($this->client_id); $client->setClientSecret($this->client_secret); $client->setRedirectUri($this->redirect_uri); $client->addScope("openid email"); $authUrl = $client->createAuthUrl(); return $authUrl; }
public function index() { // パスが通っていなければ設定 $path = 'http://192.168.99.21/app/Vendor/google-api-php-client/src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); App::import('Vendor', 'Google_Client', array('file' => 'google-api-php-client/src/Google/Client.php')); App::import('Vendor', 'Google_Service', array('file' => 'google-api-php-client/src/Google/Service.php')); App::import('Vendor', 'Google_Service_Model', array('file' => 'google-api-php-client/src/Google/Model.php')); App::import('Vendor', 'Google_Service_Collection', array('file' => 'google-api-php-client/src/Google/Collection.php')); App::import('Vendor', 'Google_Service_Resource', array('file' => 'google-api-php-client/src/Google/Service/Resource.php')); App::import('Vendor', 'Google_Service_Analytics', array('file' => 'google-api-php-client/src/Google/Service/Analytics.php')); // Google Developers Consoleで作成されたクライアントID define('CLIENT_ID', '3274760987-rec90linuevn0ahdi5ck5212gg54m3ur.apps.googleusercontent.com'); // Google Developers Consoleで作成されたクライアントシークレット define('CLIENT_SECRET', 'F_aDjo5IqA2Zn4Dz7gA4sgAm'); // Google Developers Consoleで作成されたリダイレクトURI define('REDIRECT_URI', 'http://' . $_SERVER['HTTP_HOST'] . '/analytics'); $client = new Google_Client(); $client->setClientId(CLIENT_ID); $client->setClientSecret(CLIENT_SECRET); $client->setRedirectUri(REDIRECT_URI); $client->addScope('https://www.googleapis.com/auth/analytics.readonly'); $analytics = new Google_Service_Analytics($client); // 認証後codeを受け取ったらセッション保存 if (isset($this->request->query['code'])) { $client->authenticate($this->request->query['code']); $this->Session->write('token', $client->getAccessToken()); $this->redirect('http://' . $_SERVER['HTTP_HOST'] . '/analytics'); } if ($this->Session->check('token')) { $client->setAccessToken($this->Session->read('token')); } if ($client->getAccessToken()) { $start_date = date('Y-m-d', strtotime('- 10 day')); $end_date = date('Y-m-d'); // GoogleAnalyticsの「アナリティクス設定」>「ビュー」>「ビュー設定」の「ビューID」 $view = '106133184'; // データ取得 $data = array(); $dimensions = 'ga:date'; $metrics = 'ga:visits'; $sort = 'ga:date'; $optParams = array('dimensions' => $dimensions, 'sort' => $sort); $results = $analytics->data_ga->get('ga:' . $view, $start_date, $end_date, $metrics, $optParams); if (isset($results['rows']) && !empty($results['rows'])) { $data['Sample']['date'] = $results['rows'][0][0]; $data['Sample']['visits'] = $results['rows'][0][1]; } pr($data); } else { $auth_url = $client->createAuthUrl(); echo '<a href="' . $auth_url . '">認証</a>'; } exit; }
private function init() { if ($this->client == null) { $client = new Google_Client(); $client->setClientId($this->getClientID()); $client->setClientSecret($this->getSecret()); $client->setRedirectUri($this->getRedirect()); // $client->setApplicationName("Open eClass"); $client->addScope(Google_Service_Drive::DRIVE); $this->client = $client; } }
/** * */ protected function _setGoogleClient() { $googleClient = new Google_Client(); $googleClient->setAuthConfigFile($this->_getConfigFilePath()); $googleClient->addScope($this->_getScopes()); $googleClient->setRedirectUri(Router::url(array('plugin' => 'auth_manager', 'controller' => 'media_platform_users', 'action' => 'callback', $this->_getPlatformId()), true)); // This will force Google to always return the refresh_token. $googleClient->setAccessType('offline'); $googleClient->setApprovalPrompt('force'); $this->_client = $googleClient; }
public function testPrepareService() { $client = new Google_Client(); $client->setScopes(array("scope1", "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals("scope1 scope2", $scopes); $client->setScopes(array("", "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals(" scope2", $scopes); $client->setScopes("scope2"); $client->addScope("scope3"); $client->addScope(array("scope4", "scope5")); $scopes = $client->prepareScopes(); $this->assertEquals("scope2 scope3 scope4 scope5", $scopes); $client->setClientId('test1'); $client->setRedirectUri('http://localhost/'); $client->setScopes(array("http://test.com", "scope2")); $scopes = $client->prepareScopes(); $this->assertEquals("http://test.com scope2", $scopes); $this->assertEquals('' . 'https://accounts.google.com/o/oauth2/auth' . '?response_type=code&redirect_uri=http%3A%2F%2Flocalhost%2F' . '&client_id=test1' . '&scope=http%3A%2F%2Ftest.com+scope2&access_type=online' . '&approval_prompt=auto', $client->createAuthUrl()); // This should not trigger a request. $client->setDefer(true); $dr_service = new Google_Service_Drive($client); $this->assertInstanceOf('Google_Http_Request', $dr_service->files->listFiles()); }