Example #1
5
 function google()
 {
     $client = new Google_Client();
     $client->setApplicationName("snmmaurya");
     $client->setClientId(CLIENT_ID);
     $client->setClientSecret(CLIENT_SECRET);
     $client->setRedirectUri(REDIRECT_URI);
     $client->setApprovalPrompt(APPROVAL_PROMPT);
     $client->setAccessType(ACCESS_TYPE);
     $oauth2 = new Google_Oauth2Service($client);
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['token'] = $client->getAccessToken();
     }
     if (isset($_SESSION['token'])) {
         $client->setAccessToken($_SESSION['token']);
     }
     if (isset($_REQUEST['error'])) {
         echo '<script type="text/javascript">window.close();</script>';
         exit;
     }
     if ($client->getAccessToken()) {
         $user = $oauth2->userinfo->get();
         $_SESSION['User'] = $user;
         $_SESSION['token'] = $client->getAccessToken();
     } else {
         $authUrl = $client->createAuthUrl();
         header('Location: ' . $authUrl);
     }
 }
Example #2
3
 public function actionToken()
 {
     //$this->checkAccess("token");
     $client = new \Google_Client();
     $client->setClientId(Yii::$app->params['OAUTH2_CLIENT_ID']);
     $client->setClientSecret(Yii::$app->params['OAUTH2_CLIENT_SECRET']);
     $client->setScopes('https://www.googleapis.com/auth/youtube');
     //$redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], FILTER_SANITIZE_URL);
     $client->setRedirectUri(Yii::$app->params['redirectVideo']);
     if (Yii::$app->request->get('code')) {
         if (strval(Yii::$app->session->get('state')) !== strval(Yii::$app->request->get('state'))) {
             die('The session state did not match.');
         }
         $client->authenticate(Yii::$app->request->get('code'));
         if ($client->getAccessToken()) {
             $token = $this->getToken();
             $token->load(json_decode($client->getAccessToken(), true), "");
             $token->save();
             return ["token_saved" => $token];
         }
         return ["token_not_saved_code" => Yii::$app->request->get('code')];
     }
     if (!$client->getAccessToken()) {
         // If the user hasn't authorized the app, initiate the OAuth flow
         //$state = mt_rand();
         $client->setState(Yii::$app->params['stateVideo']);
         $client->setAccessType("offline");
         $client->setApprovalPrompt("force");
         Yii::$app->session->set('state', Yii::$app->params['stateVideo']);
         $authUrl = $client->createAuthUrl();
         return ["link" => $authUrl];
     }
 }
 /**
  * Returns an authorized API client.
  * @return Google_Client the authorized client object
  */
 private function getGoogleApiClient()
 {
     $client = new Google_Client();
     $client->setApplicationName($this->CFG['GOOGLE_API_APPLICATION_NAME']);
     $client->setScopes(Google_Service_Calendar::CALENDAR);
     $client->setAuthConfigFile($this->CFG['GOOGLE_API_CLIENT_SECRET_PATH']);
     $client->setAccessType('offline');
     // Load previously authorized credentials from a file.
     $credentialsPath = $this->CFG['GOOGLE_API_CREDENTIALS_PATH'];
     if (file_exists($credentialsPath)) {
         $accessToken = file_get_contents($credentialsPath);
     } else {
         // Request authorization from the user.
         $authUrl = $client->createAuthUrl();
         printf("Open the following link in your browser:\n%s\n", $authUrl);
         print 'Enter verification code: ';
         $authCode = trim(fgets(STDIN));
         // Exchange authorization code for an access token.
         $accessToken = $client->authenticate($authCode);
         // Store the credentials to disk.
         if (!file_exists(dirname($credentialsPath))) {
             mkdir(dirname($credentialsPath), 0700, true);
         }
         file_put_contents($credentialsPath, $accessToken);
         printf("Credentials saved to %s\n", $credentialsPath);
     }
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($credentialsPath, $client->getAccessToken());
     }
     return $client;
 }
Example #4
1
 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;
         }
     }
 }
Example #5
1
 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());
 }
Example #6
0
 /**
  * @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');
 }
 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'));
     }
 }
/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient()
{
    global $credentialsPath;
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(GAPI_SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');


    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        die("Please, get token via connect.php");
    }

    $client->setAccessToken($accessToken);

    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
        $client = refreshToken($client);
    }

    return $client;
}
 /**
  * Change the access type of the calendar
  *
  * @param string $type
  * @throws \KevinDitscheid\KdCalendar\Exception\AccessTypeNotSupportedException
  */
 public function changeAccessType($type)
 {
     if ($type !== self::ACCESS_TYPE_ONLINE || $type !== self::ACCESS_TYPE_OFFLINE) {
         throw new \KevinDitscheid\KdCalendar\Exception\AccessTypeNotSupportedException("The access type \"{$type}\" is not supported!", 1454959656);
     }
     $this->client->setAccessType($type);
 }
 /**
  * @throws MissingConfigurationException
  * @return \Google_Client
  */
 public function create()
 {
     $client = new \Google_Client();
     $requiredAuthenticationSettings = array('applicationName', 'clientId', 'clientSecret', 'developerKey');
     foreach ($requiredAuthenticationSettings as $key) {
         if (!isset($this->authenticationSettings[$key])) {
             throw new MissingConfigurationException(sprintf('Missing setting "TYPO3.Neos.GoogleAnalytics.authentication.%s"', $key), 1415796352);
         }
     }
     $client->setApplicationName($this->authenticationSettings['applicationName']);
     $client->setClientId($this->authenticationSettings['clientId']);
     $client->setClientSecret($this->authenticationSettings['clientSecret']);
     $client->setDeveloperKey($this->authenticationSettings['developerKey']);
     $client->setScopes(array('https://www.googleapis.com/auth/analytics.readonly'));
     $client->setAccessType('offline');
     $accessToken = $this->tokenStorage->getAccessToken();
     if ($accessToken !== NULL) {
         $client->setAccessToken($accessToken);
         if ($client->isAccessTokenExpired()) {
             $refreshToken = $this->tokenStorage->getRefreshToken();
             $client->refreshToken($refreshToken);
         }
     }
     return $client;
 }
function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    $credentialsPath = CREDENTIALS_PATH;
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n%s\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        $accessToken = $client->authenticate($authCode);
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
Example #12
0
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;
}
 /**
  *  get google client
  *  @return Google_Client the authorized client object
  */
 public static function getClient()
 {
     // $scopes = implode(' ', [Google_Service_Gmail::GMAIL_READONLY]);
     /*
         $scopes = [
             'https://www.googleapis.com/auth/gmail.readonly',
             'https://www.googleapis.com/auth/gmail.modify',
             'https://www.googleapis.com/auth/gmail.send',
         ];
     */
     $scopes = ['https://mail.google.com/'];
     $clientSecretFile = conf('gmail.client_secret');
     if (!file_exists($clientSecretFile)) {
         pr('Error: client secret file not found', true);
         pr('Please create "OAuth 2.0 client IDs"');
         pr('login to https://console.developers.google.com/apis/credentials/');
         exit;
     }
     $client = new Google_Client();
     $client->setScopes($scopes);
     $client->setAuthConfigFile($clientSecretFile);
     $client->setAccessType('offline');
     // $client->setApprovalPrompt('force');
     $tokenFile = conf('gmail.access_token');
     $accessToken = self::accessToken($client, $tokenFile);
     $client->setAccessToken($accessToken);
     // Refresh the token if it's expired.
     if ($client->isAccessTokenExpired()) {
         $client->refreshToken($client->getRefreshToken());
         file_put_contents($tokenFile, $client->getAccessToken());
     }
     return $client;
 }
 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;
     }
 }
Example #15
0
 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);
 }
Example #16
0
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;
}
Example #17
0
 public function callback()
 {
     $client = new Google_Client();
     $client->setApplicationName($this->__app_name);
     $client->setClientId($this->__client_id);
     $client->setClientSecret($this->__client_secret);
     $client->setRedirectUri($this->__redirect_uri);
     $client->setDeveloperKey($this->__develop_key);
     $client->setScopes('https://www.googleapis.com/auth/calendar');
     $client->setAccessType('offline');
     if (isset($_GET['code'])) {
         $client->authenticate($_GET['code']);
         $_SESSION['token'] = $client->getAccessToken();
         $this->Session->delete('HTTP_REFERER');
         header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
     }
     // 呼び出し先
     if (isset($_SESSION['oauth_referer'])) {
         $url = $_SESSION['oauth_referer'];
         $this->Session->delete('oauth_referer');
     } else {
         $url = 'index';
     }
     $this->redirect('/');
 }
Example #18
0
 /**
  * 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;
 }
Example #19
0
function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET);
    $client->setAccessType('offline');
    // Load previously authorized credentials from a file.
    $credentialsPath = expandHomeDirectory(CREDENTIAL_PATH);
    if (file_exists($credentialsPath)) {
        $accessToken = file_get_contents($credentialsPath);
    } else {
        // Request authorization from the user.
        $authUrl = $client->createAuthUrl();
        printf("Open the following link in your browser:\n\n\t%s\n\n", $authUrl);
        print 'Enter verification code: ';
        $authCode = trim(fgets(STDIN));
        // Exchange authorization code for an access token.
        $accessToken = $client->authenticate($authCode);
        // Store the credentials to disk.
        if (!file_exists(dirname($credentialsPath))) {
            mkdir(dirname($credentialsPath), 0700, true);
        }
        file_put_contents($credentialsPath, $accessToken);
        printf("Credentials saved to %s\n", $credentialsPath);
    }
    $client->setAccessToken($accessToken);
    // Refresh the token if it's expired.
    if ($client->isAccessTokenExpired()) {
        $client->refreshToken($client->getRefreshToken());
        file_put_contents($credentialsPath, $client->getAccessToken());
    }
    return $client;
}
 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;
 }
Example #21
0
 /**
  * Constructor stores the passed Google Client object, sets a bunch of config options from the config file, and also
  * creates and instance of the \Google_Service_YouTube class and stores this for later use.
  *
  * @param \Google_Client $client
  */
 public function __construct(\Google_Client $client)
 {
     $this->client = $client;
     $this->client->setApplicationName(\Config::get('laravel-youtube::application_name'));
     $this->client->setClientId(\Config::get('laravel-youtube::client_id'));
     $this->client->setClientSecret(\Config::get('laravel-youtube::client_secret'));
     $this->client->setScopes(\Config::get('laravel-youtube::scopes'));
     $this->client->setAccessType(\Config::get('laravel-youtube::access_type'));
     $this->client->setApprovalPrompt(\Config::get('laravel-youtube::approval_prompt'));
     $this->client->setRedirectUri(\URL::to(\Config::get('laravel-youtube::redirect_uri')));
     $this->client->setClassConfig('Google_Http_Request', 'disable_gzip', true);
     $this->youtube = new \Google_Service_YouTube($this->client);
     $accessToken = $this->getLatestAccessTokenFromDB();
     if ($accessToken) {
         $this->client->setAccessToken($accessToken);
     }
 }
Example #22
0
 public function __construct(\Google_Client $client)
 {
     $client->setApplicationName("magicpi");
     $client->setScopes([\Google_Service_Calendar::CALENDAR_READONLY]);
     $client->setAuthConfigFile(__DIR__ . "/../config/piauth.json");
     $client->setAccessType('offline');
     $client->setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/auth');
     $this->client = $client;
 }
Example #23
0
 /**
  * @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();
 }
Example #24
0
 /**
  * Returns an authorized API client.
  * @return Google_Client the authorized client object
  */
 public static function getClient()
 {
     $client = new Google_Client();
     $client->setApplicationName(static::$applicationName);
     $client->setAssertionCredentials(new Google_Auth_AssertionCredentials(static::$serviceAccount['email'], static::$driveScope, file_get_contents(__DIR__ . '/' . static::$serviceAccount['keyPath'])));
     $client->setAccessType('offline');
     $client->setClassConfig('Google_Cache_File', array('directory' => '/tmp/cache'));
     return $client;
 }
Example #25
0
/**
 * Returns an authorized API client.
 * @return Google_Client the authorized client object
 */
function getClient()
{
    $client = new Google_Client();
    $client->setApplicationName(APPLICATION_NAME);
    $client->setScopes(SCOPES);
    $client->setAuthConfigFile(CLIENT_SECRET_PATH);
    $client->setAccessType('offline');
    $client->setRedirectUri('http://localhost/gmail/index.php');
    return $client;
}
Example #26
0
 private static function getClient()
 {
     $scopes = implode(' ', array(Google_Service_Calendar::CALENDAR));
     $client = new Google_Client();
     $client->setApplicationName('s1704362\'s Study Website');
     $client->setScopes($scopes);
     $client->setAuthConfigFile('app/config/client_secret.json');
     $client->setAccessType('offline');
     return $client;
 }
Example #27
0
 /**
  * @param array $config
  */
 public function __construct(array $config)
 {
     $this->config = $config;
     // create an instance of the google client for OAuth2
     $this->client = new \Google_Client();
     // set application name
     $this->client->setApplicationName(array_get($config, 'application_name', ''));
     // set oauth2 configs
     $this->client->setClientId(array_get($config, 'client_id', ''));
     $this->client->setClientSecret(array_get($config, 'client_secret', ''));
     $this->client->setRedirectUri(array_get($config, 'redirect_uri', ''));
     $this->client->setScopes(array_get($config, 'scopes', []));
     $this->client->setAccessType(array_get($config, 'access_type', 'online'));
     $this->client->setApprovalPrompt(array_get($config, 'approval_prompt', 'auto'));
     // set developer key
     $this->client->setDeveloperKey(array_get($config, 'developer_key', ''));
     // auth for service account
     $this->auth();
 }
 /**
  * Returns an authorized API client.
  *
  * @return \Google_Client the authorized client object
  */
 public function getClient()
 {
     $client = new \Google_Client();
     $client->setApplicationName($this->applicationName);
     $client->setScopes(implode(' ', $this->scopes));
     $client->setAuthConfigFile($this->authConfigFile);
     $client->setAccessType('offline');
     $client->setApprovalPrompt('force');
     return $client;
 }
 static function get_client()
 {
     $client = new Google_Client();
     $client->setApplicationName('rc-google-addressbook');
     $client->setScopes("http://www.google.com/m8/feeds/");
     $client->setClientId('775403024003-e5m4h02j1hsgjj0dipef3ugbg8ee9emb.apps.googleusercontent.com');
     $client->setClientSecret('HcRLtRTEGIqScjMpkREddO6L');
     $client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');
     $client->setAccessType('offline');
     return $client;
 }
Example #30
-1
 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;
 }