diff --git a/app/Http/Controllers/AnagraficaController.php b/app/Http/Controllers/AnagraficaController.php index 03a1baa..4bc9e86 100644 --- a/app/Http/Controllers/AnagraficaController.php +++ b/app/Http/Controllers/AnagraficaController.php @@ -5,10 +5,74 @@ namespace App\Http\Controllers; use App\Models\anagrafica; use App\Models\contatto; use Illuminate\Http\Request; +use Google\Client; +Use Google\Service\PeopleService; class AnagraficaController extends Controller { - // + // GOOGLE CONTACTS PART + + private $google_client; + + /* public function getToken() + { + $client = new Client(); + $client->setApplicationName('gestionale.lavorain.cloud'); + if(!is_null($client->getAccessToken())){} + elseif(!is_null(session('access_token'))) // is_null(Session::get('access_token', null)) + { + $client->setAccessToken(session('access_token')); + } + else + { + $scope = array(); + $scope[] = 'https://www.googleapis.com/auth/contacts'; + // $client-> + putenv('GOOGLE_APPLICATION_CREDENTIALS='.storage_path('app/google-calendar/service_key.json')); //this can be created with other ENV mode server side + $client->useApplicationDefaultCredentials(); + $token = $client->getAccessToken(); + session(['access_token' => $token]); + } + return $client; + }*/ + + public function getGoogleContacts() + { + $client = $this->getToken(); + $service = new PeopleService($client); + $profile = $service->people_connections->listPeopleConnections('people/me', array('personFields' => 'names,emailAddresses,phoneNumbers')); + } + public function getToken() + { + $configJson =storage_path('app/google-calendar/service_key.json'); + //$configJson =storage_path('app/google-calendar/people.json'); + // define an application name + $applicationName = 'gestionale-di-famiglia'; + + // create the client + $client = new \Google_Client(); + $client->setApplicationName($applicationName); + $client->setAuthConfig($configJson); + $client->setAccessType('offline'); // necessary for getting the refresh token + $client->setApprovalPrompt ('force'); // necessary for getting the refresh token + // scopes determine what google endpoints we can access. keep it simple for now. + + $client->setScopes( + [ + /*\Google\Service\Oauth2::USERINFO_PROFILE, + \Google\Service\Oauth2::USERINFO_EMAIL, + \Google\Service\Oauth2::OPENID,*/ + \Google\Service\PeopleService::CONTACTS // allows reading of google drive metadata + ] + ); + $client->setIncludeGrantedScopes(true); + + return $client; + } + + + + public function newContact() { return view('anagrafica.form'); diff --git a/composer.json b/composer.json index d4d76af..1793933 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "creativeorange/gravatar": "^1.0", "directorytree/ldaprecord": "^2.9", "fruitcake/laravel-cors": "^2.0", + "google/apiclient": "^2.15.0", "guzzlehttp/guzzle": "^7.0.1", "jeroennoten/laravel-adminlte": "^3.9", "laravel-notification-channels/telegram": "^2.0", diff --git a/composer.lock b/composer.lock index 194b19d..102c5ec 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fee26f6948b0082f65e8b7afbce9c24b", + "content-hash": "c58658999463fa4485159d5f4dde1d96", "packages": [ { "name": "almasaeed2010/adminlte", diff --git a/routes/admin.php b/routes/admin.php index 92b2127..fc5440d 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -211,4 +211,5 @@ Route::group(['middleware'=>['permission:meetingroom']], function(){ Route::get('testmail',function(){ $name='Flavio'; Mail::to('flavio.barachino@lavorain.cloud')->send(new myTestEmail($name)); - });*/ \ No newline at end of file + });*/ + Route::get('test/google',[AnagraficaController::class,'getGoogleContacts']); \ No newline at end of file