public function __construct($username) { $service_name = 'drive'; // $key = get_config('morsle','privatekey'); // $this->privatekey = json_decode($key); // var_dump($key); // die; $this->client = new Google_Client(); $this->client_id = '1016393342084-dqql4goj9s0l402sbf4dtnoq2tsk0hp8.apps.googleusercontent.com'; $this->service_account_name = '*****@*****.**'; $this->client->addScope("https://www.googleapis.com/auth/drive"); $this->client->addScope("https://www.googleapis.com/auth/drive.file"); $this->client->addScope('https://spreadsheets.google.com/feeds'); $this->service = new Google_Service_Drive($this->client); $this->auth = service_account($this->client, $this->client_id, $this->service_account_name, $username); $this->revoke_token(); $this->auth = service_account($this->client, $this->client_id, $this->service_account_name, $username); }
function get_token($service_name) { $this->setup_client(); $auth = ''; switch ($service_name) { case 'calendar': $auth = $this->cal_auth; $this->service = new Google_Service_Calendar($this->client); $this->auth = service_account($this->client, $this->useremail, $auth); $this->revoke_token(); $this->auth = service_account($this->client, $this->useremail, $auth); $this->update_timezone(); break; case 'drive': $auth = $this->drive_auth; $this->service = new Google_Service_Drive($this->client); $this->auth = service_account($this->client, $this->useremail, $auth); $this->revoke_token(); $this->auth = service_account($this->client, $this->useremail, $auth); break; case 'file': $auth = $this->drive_auth; $this->service = new Google_Service_Drive_DriveFile($this->client); $this->auth = service_account($this->client, $this->useremail, $auth); $this->revoke_token(); $this->auth = service_account($this->client, $this->useremail, $auth); break; case 'user': $auth = $this->user_auth; $this->service = new Google_Service_Directory($this->client); $this->user = new Google_Service_Directory_User(); $this->name = new Google_Service_Directory_UserName(); $this->auth = service_account($this->client, $this->useremail, $auth); $this->revoke_token(); $this->auth = service_account($this->client, $this->useremail, $auth); break; case 'group': $auth = $this->group_auth; $this->service = new Google_Service_Directory($this->client); $this->group = new Google_Service_Directory_Group(); $this->revoke_token(); $this->auth = service_account($this->client, $this->useremail, $auth); break; } }