IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

Insertion d'un évènement dans Google Agenda en Php


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mai 2015
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Hauts de Seine (Île de France)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Mai 2015
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Insertion d'un évènement dans Google Agenda en Php
    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 :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    <?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.googleusercontent.com");
        $client->setDeveloperKey('AIzaSyDQ3Dov7U25n0mWKQKn6rC1N2DbOZLpkFE'); //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:protected] => recurrence [internal_gapi_mappings:protected] => Array ( ) [anyoneCanAddSelf] => [attendeesType:protected] => Google_Service_Calendar_EventAttendee [attendeesDataType:protected] => array [attendeesOmitted] => [colorId] => [created] => [creatorType:protected] => Google_Service_Calendar_EventCreator [creatorDataType:protected] => [description] => [endType:protected] => Google_Service_Calendar_EventDateTime [endDataType:protected] => [endTimeUnspecified] => [etag] => [extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties [extendedPropertiesDataType:protected] => [gadgetType:protected] => Google_Service_Calendar_EventGadget [gadgetDataType:protected] => [guestsCanInviteOthers] => [guestsCanModify] => [guestsCanSeeOtherGuests] => [hangoutLink] => [htmlLink] => [iCalUID] => [id] => [kind] => [location] => Suresnes [locked] => [organizerType:protected] => Google_Service_Calendar_EventOrganizer [organizerDataType:protected] => [originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime [originalStartTimeDataType:protected] => [privateCopy] => [recurrence] => [recurringEventId] => [remindersType:protected] => Google_Service_Calendar_EventReminders [remindersDataType:protected] => [sequence] => [sourceType:protected] => Google_Service_Calendar_EventSource [sourceDataType:protected] => [startType:protected] => Google_Service_Calendar_EventDateTime [startDataType:protected] => [status] => [summary] => Insertion Evenement [transparency] => [updated] => [visibility] => [modelData:protected] => Array ( ) [processed:protected] => Array ( ) [start] => Google_Service_Calendar_EventDateTime Object ( [internal_gapi_mappings:protected] => Array ( ) [date] => [dateTime] => 2015-05-27T19:00:00.000+01:00 [timeZone] => Europe/Paris [modelData:protected] => Array ( ) [processed:protected] => Array ( ) ) [end] => Google_Service_Calendar_EventDateTime Object ( [internal_gapi_mappings:protected] => Array ( ) [date] => [dateTime] => 2015-05-27T19:25:00.000+01:00 [timeZone] => Europe/Paris [modelData:protected] => Array ( ) [processed:protected] => Array ( ) ) ) )

    Calendar insert01 : ID : Google_Service_Calendar_Event Object ( [collection_key:protected] => recurrence [internal_gapi_mappings:protected] => Array ( ) [anyoneCanAddSelf] => [attendeesType:protected] => Google_Service_Calendar_EventAttendee [attendeesDataType:protected] => array [attendeesOmitted] => [colorId] => [created] => [creatorType:protected] => Google_Service_Calendar_EventCreator [creatorDataType:protected] => [description] => [endType:protected] => Google_Service_Calendar_EventDateTime [endDataType:protected] => [endTimeUnspecified] => [etag] => [extendedPropertiesType:protected] => Google_Service_Calendar_EventExtendedProperties [extendedPropertiesDataType:protected] => [gadgetType:protected] => Google_Service_Calendar_EventGadget [gadgetDataType:protected] => [guestsCanInviteOthers] => [guestsCanModify] => [guestsCanSeeOtherGuests] => [hangoutLink] => [htmlLink] => [iCalUID] => [id] => [kind] => [location] => [locked] => [organizerType:protected] => Google_Service_Calendar_EventOrganizer [organizerDataType:protected] => [originalStartTimeType:protected] => Google_Service_Calendar_EventDateTime [originalStartTimeDataType:protected] => [privateCopy] => [recurrence] => [recurringEventId] => [remindersType:protected] => Google_Service_Calendar_EventReminders [remindersDataType:protected] => [sequence] => [sourceType:protected] => Google_Service_Calendar_EventSource [sourceDataType:protected] => [startType:protected] => Google_Service_Calendar_EventDateTime [startDataType:protected] => [status] => [summary] => [transparency] => [updated] => [visibility] => [modelData:protected] => Array ( [error] => Array ( [errors] => Array ( [0] => Array ( [domain] => global [reason] => required [message] => Login Required [locationType] => header [location] => Authorization ) ) [code] => 401 [message] => Login Required ) ) [processed:protected] => 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.
    Images attachées Images attachées   

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Je n'ai plus d'exemple sous la main mais pour avoir un accès en écriture, il faut s'authentifier, les tokens ne suffisent pas :
    https://developers.google.com/google-apps/calendar/auth
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

Discussions similaires

  1. [WD17] Supprimer un rdv dans Google Agenda
    Par jer64 dans le forum WinDev
    Réponses: 1
    Dernier message: 06/01/2014, 00h13
  2. [WD17] Ajout d'un lieu de rdv dans google Agenda
    Par jer64 dans le forum WinDev
    Réponses: 1
    Dernier message: 05/01/2014, 19h32
  3. Google ajoute la prise de rendez-vous dans Google Agenda
    Par Gordon Fowler dans le forum Cloud Computing
    Réponses: 1
    Dernier message: 22/06/2011, 14h22
  4. Réponses: 0
    Dernier message: 01/09/2008, 19h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo