Bonjour
Insertion d'un évènement dans Google Agenda en Php : mise à jour impossible.
Avant de développer un composant qui permet une mise à jour de Google Calendar, j'ai souhaité testé la solution en utilisant un simple script Php.
J'essaie d'insérer un évènement dans Google Agenda à partir d'une application Php.
J'ai installé Google library sous un répertoire. Vous trouverez en pièces jointes des copies écran :
- l'écran Google developpers console
- les paramètres de l'agenda
J'ai utilisé avec succés dans un script php les fonctions de lecture dans l'agenda. Par contre imopssible d'effectuer une insertion dans cet agenda.
Pour mettre à jour cet agenda j'utilise le script php suivant :
<?php
//INCLUDE THE GOOGLE API PHP CLIENT LIBRARY FOUND HERE
//https://github.com/google/google-api-php-client
//DOWNLOAD IT AND PUT IT ON YOUR WEBSERVER IN THE ROOT FOLDER.
include(__DIR__.'/google-api-php-client-master/src/Google/autoload.php');
require_once (__DIR__.'/google-api-php-client-master/src/Google/Client.php');
require_once (__DIR__.'/google-api-php-client-master/src/Google/Service/Calendar.php');
$client = new Google_Client();
// $client->setUseObjects(true);
$client->setApplicationName("mycalendar");
$client->setClientId("78799027402-584akf302keocfs2a0d1dskv8bt5lj54.apps.googleuserco ntent.com");
$client->setDeveloperKey('AIzaSyDQ3Dov7U25n0mWKQKn6rC1N2Db OZLpkFE'); //GET AT AT DEVELOPERS.GOOGLE.COM
//
$service = new Google_Service_Calendar($client);
//
$event = new Google_Service_Calendar_Event();
$event->setSummary('Event 1');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2015-05-26T19:00:00.000+01:00');
$start->setTimeZone('Europe/Paris');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2015-05-26T19:25:00.000+01:00');
$end->setTimeZone('Europe/Paris');
$event->setEnd($end);
//
$calendar_id = "paul.xxxxx@gmail.com";
//
$new_event = null;
//
try {
$new_event = $service->events->insert($calendar_id, $event);
//
$new_event_id = $new_event->getId();
} catch (Google_ServiceException $e) {
syslog(LOG_ERR, $e->getMessage());
}
?>
L'instruction $new_event = $service->events->insert($calendar_id, $event); fait appel à la fonction insert de Calendar.php.
Ci dessous une copie de cette fonction avec l'ajout d'instructions echo pour afficher certaines variables.
public function insert($calendarId, Google_Service_Calendar_Event $postBody, $optParams = array())
{
$params = array('calendarId' => $calendarId, 'postBody' => $postBody);
$params = array_merge($params, $optParams);
echo "Calendar insert00 : $calendarId<br>";
echo "<br><br><br>";
print_r($params);
$Id = $this->call('insert', array($params), "Google_Service_Calendar_Event");
echo "<br><br>Calendar insert01 : ID : ";
print_r($Id);
return $Id;
// return $this->call('insert', array($params), "Google_Service_Calendar_Event");
}
L'instruction $this->call('insert', array($params), "Google_Service_Calendar_Event");
fait appel à la fonction call de Resource.php.
L'instruction print_r($Id);
déclenche l'affichage des données de retour de call('insert'.
Calendar insert00 : Array ( [calendarId] => paul.terce@gmail.com [postBody] => Google_Service_Calendar_Event Object ( [collection_key
rotected] => recurrence [internal_gapi_mappings
rotected] => Array ( ) [anyoneCanAddSelf] => [attendeesType
rotected] => Google_Service_Calendar_EventAttendee [attendeesDataType
rotected] => array [attendeesOmitted] => [colorId] => [created] => [creatorType
rotected] => Google_Service_Calendar_EventCreator [creatorDataType
rotected] => [description] => [endType
rotected] => Google_Service_Calendar_EventDateTime [endDataType
rotected] => [endTimeUnspecified] => [etag] => [extendedPropertiesType
rotected] => Google_Service_Calendar_EventExtendedProperties [extendedPropertiesDataType
rotected] => [gadgetType
rotected] => Google_Service_Calendar_EventGadget [gadgetDataType
rotected] => [guestsCanInviteOthers] => [guestsCanModify] => [guestsCanSeeOtherGuests] => [hangoutLink] => [htmlLink] => [iCalUID] => [id] => [kind] => [location] => Suresnes [locked] => [organizerType
rotected] => Google_Service_Calendar_EventOrganizer [organizerDataType
rotected] => [originalStartTimeType
rotected] => Google_Service_Calendar_EventDateTime [originalStartTimeDataType
rotected] => [privateCopy] => [recurrence] => [recurringEventId] => [remindersType
rotected] => Google_Service_Calendar_EventReminders [remindersDataType
rotected] => [sequence] => [sourceType
rotected] => Google_Service_Calendar_EventSource [sourceDataType
rotected] => [startType
rotected] => Google_Service_Calendar_EventDateTime [startDataType
rotected] => [status] => [summary] => Insertion Evenement [transparency] => [updated] => [visibility] => [modelData
rotected] => Array ( ) [processed
rotected] => Array ( ) [start] => Google_Service_Calendar_EventDateTime Object ( [internal_gapi_mappings
rotected] => Array ( ) [date] => [dateTime] => 2015-05-27T19:00:00.000+01:00 [timeZone] => Europe/Paris [modelData
rotected] => Array ( ) [processed
rotected] => Array ( ) ) [end] => Google_Service_Calendar_EventDateTime Object ( [internal_gapi_mappings
rotected] => Array ( ) [date] => [dateTime] => 2015-05-27T19:25:00.000+01:00 [timeZone] => Europe/Paris [modelData
rotected] => Array ( ) [processed
rotected] => Array ( ) ) ) )
Calendar insert01 : ID : Google_Service_Calendar_Event Object ( [collection_key
rotected] => recurrence [internal_gapi_mappings
rotected] => Array ( ) [anyoneCanAddSelf] => [attendeesType
rotected] => Google_Service_Calendar_EventAttendee [attendeesDataType
rotected] => array [attendeesOmitted] => [colorId] => [created] => [creatorType
rotected] => Google_Service_Calendar_EventCreator [creatorDataType
rotected] => [description] => [endType
rotected] => Google_Service_Calendar_EventDateTime [endDataType
rotected] => [endTimeUnspecified] => [etag] => [extendedPropertiesType
rotected] => Google_Service_Calendar_EventExtendedProperties [extendedPropertiesDataType
rotected] => [gadgetType
rotected] => Google_Service_Calendar_EventGadget [gadgetDataType
rotected] => [guestsCanInviteOthers] => [guestsCanModify] => [guestsCanSeeOtherGuests] => [hangoutLink] => [htmlLink] => [iCalUID] => [id] => [kind] => [location] => [locked] => [organizerType
rotected] => Google_Service_Calendar_EventOrganizer [organizerDataType
rotected] => [originalStartTimeType
rotected] => Google_Service_Calendar_EventDateTime [originalStartTimeDataType
rotected] => [privateCopy] => [recurrence] => [recurringEventId] => [remindersType
rotected] => Google_Service_Calendar_EventReminders [remindersDataType
rotected] => [sequence] => [sourceType
rotected] => Google_Service_Calendar_EventSource [sourceDataType
rotected] => [startType
rotected] => Google_Service_Calendar_EventDateTime [startDataType
rotected] => [status] => [summary] => [transparency] => [updated] => [visibility] => [modelData
rotected] => Array ( [error] => Array ( [errors] => Array ( [0] => Array ( [domain] => global [reason] => required [message] => Login Required [locationType] => header [location] => Authorization ) ) [code] => 401 [message] => Login Required ) ) [processed
rotected] => Array ( ) )
Dans l'affichage insert01 je trouve les infos suivantes : [code] => 401 [message] => Login Required
Pourquoi il est impossible de mettre à jour cet agenda, alors qu'il est possible de lire les évènements. J'ai pourtant indiqué dans les paramètres que l'agenda était public.
Un gand merci par avance pour l'aide que vous pourrez m'apporter.
Insertion d'un évènement dans Google Agenda en Php : mise à jour impossible.
Avant de développer un composant qui permet une mise à jour de Google Calendar, j'ai souhaité testé la solution en utilisant un simple script Php.
J'essaie d'insérer un évènement dans Google Agenda à partir d'une application Php.
J'ai installé Google library sous un répertoire. Vous trouverez en pièces jointes des copies écran :
- l'écran Google developpers console
- les paramètres de l'agenda
J'ai utilisé avec succés dans un script php les fonctions de lecture dans l'agenda. Par contre imopssible d'effectuer une insertion dans cet agenda.
Pour mettre à jour cet agenda j'utilise le script php suivant :
<?php
//INCLUDE THE GOOGLE API PHP CLIENT LIBRARY FOUND HERE
//https://github.com/google/google-api-php-client
//DOWNLOAD IT AND PUT IT ON YOUR WEBSERVER IN THE ROOT FOLDER.
include(__DIR__.'/google-api-php-client-master/src/Google/autoload.php');
require_once (__DIR__.'/google-api-php-client-master/src/Google/Client.php');
require_once (__DIR__.'/google-api-php-client-master/src/Google/Service/Calendar.php');
$client = new Google_Client();
// $client->setUseObjects(true);
$client->setApplicationName("mycalendar");
$client->setClientId("78799027402-584akf302keocfs2a0d1dskv8bt5lj54.apps.googleuserco ntent.com");
$client->setDeveloperKey('AIzaSyDQ3Dov7U25n0mWKQKn6rC1N2Db OZLpkFE'); //GET AT AT DEVELOPERS.GOOGLE.COM
//
$service = new Google_Service_Calendar($client);
//
$event = new Google_Service_Calendar_Event();
$event->setSummary('Event 1');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2015-05-26T19:00:00.000+01:00');
$start->setTimeZone('Europe/Paris');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2015-05-26T19:25:00.000+01:00');
$end->setTimeZone('Europe/Paris');
$event->setEnd($end);
//
$calendar_id = "paul.xxxxx@gmail.com";
//
$new_event = null;
//
try {
$new_event = $service->events->insert($calendar_id, $event);
//
$new_event_id = $new_event->getId();
} catch (Google_ServiceException $e) {
syslog(LOG_ERR, $e->getMessage());
}
?>
L'instruction $new_event = $service->events->insert($calendar_id, $event); fait appel à la fonction insert de Calendar.php.
Ci dessous une copie de cette fonction avec l'ajout d'instructions echo pour afficher certaines variables.
public function insert($calendarId, Google_Service_Calendar_Event $postBody, $optParams = array())
{
$params = array('calendarId' => $calendarId, 'postBody' => $postBody);
$params = array_merge($params, $optParams);
echo "Calendar insert00 : $calendarId<br>";
echo "<br><br><br>";
print_r($params);
$Id = $this->call('insert', array($params), "Google_Service_Calendar_Event");
echo "<br><br>Calendar insert01 : ID : ";
print_r($Id);
return $Id;
// return $this->call('insert', array($params), "Google_Service_Calendar_Event");
}
L'instruction $this->call('insert', array($params), "Google_Service_Calendar_Event");
fait appel à la fonction call de Resource.php.
L'instruction print_r($Id);
déclenche l'affichage des données de retour de call('insert'.
Calendar insert00 : Array ( [calendarId] => paul.terce@gmail.com [postBody] => Google_Service_Calendar_Event Object ( [collection_key






























Calendar insert01 : ID : Google_Service_Calendar_Event Object ( [collection_key
























Dans l'affichage insert01 je trouve les infos suivantes : [code] => 401 [message] => Login Required
Pourquoi il est impossible de mettre à jour cet agenda, alors qu'il est possible de lire les évènements. J'ai pourtant indiqué dans les paramètres que l'agenda était public.
Un gand merci par avance pour l'aide que vous pourrez m'apporter.