Usuario:ManuelRomero/PHP/hibridas/practica 2018 e
De WikiEducator
< Usuario:ManuelRomero | PHP | hibridas
Revisión a fecha de 21:24 14 feb 2018; ManuelRomero (Discusión | contribuciones)
/</
<?php /** * Created by PhpStorm. * User: manuel * Date: 12/02/18 * Time: 8:51 */ class Api_Google { public function __construct(){ } static public function obtener_tareas(Google_Client $client) { $tasks = new Google_Service_Tasks($client); return $tasks; } /** * @param Google_Service_Tasks $tasks * @return Google_Service_Tasks_TaskList */ static public function obtener_lista_tareas(Google_Service_Tasks $tasks) { $repartos = $tasks->tasklists->listTasklists(); return $repartos; } static public function obtener_calendario($client){ $calendar = new Google_Service_Calendar($client); } /** * @param $f fecha * add un evento en Calendar repartos */ static public function add_calendar(Google_Service_Calendar $calendar, $f) { // La fecha es correcta creamos la entrada en Calendar // Insertar evento $evento = new Google_Service_Calendar_Event(); $evento->setSummary("Repartos"); // hora de comienzo $comienzo = new Google_Service_Calendar_EventDateTime(); $comienzo->setDateTime("$fT09:00:00.000"); $comienzo->setTimeZone("Europe/Madrid"); $evento->setStart($comienzo); // hora de terminación $final = new Google_Service_Calendar_EventDateTime(); $final->setDateTime("$fT20:00:00.000"); $final->setTimeZone("Europe/Madrid"); $evento->setEnd($final); $createdEvent = $calendar->events->insert('primary', $evento); } static public function add_tarea(Google_Service_Tasks $task, $f) { $nuevalista = new Google_Service_Tasks_TaskList(); $nuevalista->setTitle("Reparto $f"); $task->tasklists->insert($nuevalista); } }
<?php require_once 'vendor/autoload.php'; class Autenticar { /** * @var Google_Client */ private $client; public function __construct() { $this->client = new Google_Client(); $this->client->setAuthConfig('/var/www/repartos/config.json'); // $this->client->setAccessType('offline'); $key = "AIzaSyARLcQ5OuAlGLxvlBf7B526mqACbXR3e1Y"; //$this->client->setDeveloperKey($key); $this->client->addScope(['https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/taskqueue', 'https://www.googleapis.com/auth/tasks']); if (!(isset($_SESSION['access_token']) && $_SESSION['access_token'])) { $this->autenticar(); } $this->client->setAccessToken($_SESSION['access_token']); } private function autenticar() { if (!isset($_GET['code'])) { $auth_url = $this->client->createAuthUrl(); header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL)); } else { $this->client->fetchAccessTokenWithAuthCode($_GET['code']); $_SESSION['access_token'] = $this->client->getAccessToken(); $redirect_uri = 'http://www.repartos.com'; header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); } } public function get_user() { return $this->client->getClientId(); } public function get_client() { return $this->client; } /** * @return Google_Service_Tasks Lista de tareas * @description Obtenemos una lista de tareas */ /** * @return Google_Service_Tasks_Tasks */ }