Ankündigung

Einklappen
Keine Ankündigung bisher.

Google Calendar - update für "neue" GoogleAPI

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

  • rok123
    antwortet
    Hallo,

    ich habe auch das Problem mit der verschobenen Stunde.
    Habe jetzt nur die googleV3.php mit meinen Codes angepasst, jedoch habe ich mir nicht die Datei vom Anhang sondern direkt den Code aus dem Beitrag kopiert (ist das der neuerste).
    Code:
    $client_id      =   '88**********.apps.googleusercontent.com';  // put your clientID here - from Google website
            $client_secret  =   'T******************U';        // put your client Secret here - from Google WebSitr
            $redirect_uri   =   'u*************b';    // put your redirect URI here from Google Website - only first line !
    
            $refresh_token  =   '1****************************************M';    // Put your google refresh token here - from other PHP script
            $calendar_id     =   $this->'b******************************0@group.calendar.google.com';    //
    Bei der Variable $calendar_id bin ich mir nicht sicher ob ich hier meinen Kalender richtig eingetragen habe.

    Einen Kommentar schreiben:


  • schloessl
    antwortet
    Zitat von bullonix Beitrag anzeigen
    Komisch jetzt wird ein code Angezeigt. Ok Jetzt beckomme ich von der googlev3.php die Fehlermeldung [{"title":"Calendar: Google","text":"Calendar read request failed!"}] . Woran kann das liegen ?
    Ich habe das gleiche Pronlem!

    php -q gogleV3.php bringt sauber meinen Kalender, nur per Programm gibt es die obige Meldung!

    Stand: Robert Beaglebone, V2.8

    Einen Kommentar schreiben:


  • bullonix
    antwortet
    Komisch jetzt wird ein code Angezeigt. Ok Jetzt beckomme ich von der googlev3.php die Fehlermeldung [{"title":"Calendar: Google","text":"Calendar read request failed!"}] . Woran kann das liegen ?

    Einen Kommentar schreiben:


  • bullonix
    antwortet
    Hallo zusammen,

    wenn ich die google_2.php ausführe bekomme ich keine Werte ausgegeben, die Seite bleibt leer.

    Kann mir jemand auf die Sprünge helfen ?

    Danke & Gruß

    Einen Kommentar schreiben:


  • schloessl
    antwortet
    erledigt!
    Zuletzt geändert von schloessl; 18.02.2016, 12:15.

    Einen Kommentar schreiben:


  • mommeke
    antwortet
    Zitat von ponG Beitrag anzeigen
    Hallo zusammen,

    hat jemand mal kürzlich versucht, die Registrierung wie im ersten Post beschrieben durchzuführen? Prinzipiell klappt das, aber es wird keine Redirect URI mehr angezeigt. Hat Google hier etwas geändert? Kennt jemand eine Lösung?

    Gruß,
    Sascha
    Redirect URI =
    Code:
    urn:ietf:wg:oauth:2.0:oob

    Einen Kommentar schreiben:


  • ponG
    antwortet
    Hallo zusammen,

    hat jemand mal kürzlich versucht, die Registrierung wie im ersten Post beschrieben durchzuführen? Prinzipiell klappt das, aber es wird keine Redirect URI mehr angezeigt. Hat Google hier etwas geändert? Kennt jemand eine Lösung?

    Gruß,
    Sascha

    Einen Kommentar schreiben:


  • schloessl
    antwortet
    Danke für die Rückmeldung!
    Alle Upates laut Forum per apt-get ausgeführt.

    Wolfgang

    Kontrolle:
    Code:
    root@ibbgateway:/home/smarthome# apt-get install curl
    Paketlisten werden gelesen... Fertig
    Abhängigkeitsbaum wird aufgebaut.
    Statusinformationen werden eingelesen.... Fertig
    curl ist schon die neueste Version.
    0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.
    root@ibbgateway:/home/smarthome# apt-get install php5-curl
    Paketlisten werden gelesen... Fertig
    Abhängigkeitsbaum wird aufgebaut.
    Statusinformationen werden eingelesen.... Fertig
    php5-curl ist schon die neueste Version.
    0 aktualisiert, 0 neu installiert, 0 zu entfernen und 0 nicht aktualisiert.

    Einen Kommentar schreiben:


  • lio123
    antwortet
    Hi Wolfgang,

    apt-get update
    apt-get install curl
    apt-get install php5-curl
    -> dann Neustart


    schon probiert?

    Einen Kommentar schreiben:


  • schloessl
    antwortet


    Zuletzt geändert von schloessl; 18.02.2016, 12:51. Grund: erledigt

    Einen Kommentar schreiben:


  • lio123
    antwortet
    habe nochmal alles frisch gemacht und kommt immer noch
    Code:
    [{"title":"Calendar: Google","text":"Calendar primary read request failed!"}]
    Gibt es eine Möglichkeit den Zugang ohne das Skript zu prüfen. Über Google API habe ich Zugriff.

    Code:
    <?php
    /**
     * -----------------------------------------------------------------------------
     * @package     smartVISU
     * @author      Martin Gleiß (basic version), Carsten Gotschlich (google API V3), Thorsten Moll (cache, multiple calendars)
     * @copyright   2012
     * @license     GPL [http://www.gnu.de]
     * -----------------------------------------------------------------------------
     */
    
    // Note: for debugging purposes you can execute this script from commandline with    php -q <scriptname>
    
    require_once '../../../lib/includes.php';
    require_once const_path_system.'calendar/calendar.php';
    require_once const_path_system.'class_cache.php';
    
    /**
     * This class reads a google calendar
     */
    class calendar_google extends calendar
    {
        const CLIENT_ID     = '81XXXXXXXXXXXXXXXXXXXXXi1qq146.apps.googleusercontent.com';    // put your clientID here - from Google website
        const CLIENT_SECRET = 'E2XXXXXXXXXXXXXXIXD';    // put your client Secret here - from Google WebSitr
        const REFRESH_TOKEN = '1/AVGXXXXXXXXXXXXXXXXXXXXXXXXXXXiATCKT';    // Put your google refresh token here - from other PHP script
    
        var $calendar_ids = array();
    
        /**
         * initialization of some parameters
         */
        public function init($request)
        {
            parent::init($request);
            if ($this->url == '')
                $this->url = 'primary';
            if ($this->count == 0)
                $this->count = 10;
    
            $this->calendar_ids = explode(',' , $this->url);
        }
    
    
        public function run()
        {
            $cache = new class_cache('calendar_google.json');
    
            // check for cached data
            if ($cache->hit(3600)) {
                $cache_content = json_decode($cache->read(), true);
    
                if ($cache_content['accessTokenExpiry'] < time()) {
                    // if token is not valid anymore reload everything cached
                    unset($cache_content);
                }
            }
    
            if (!isset($cache_content['accessToken'])) {
                $token_url = 'https://accounts.google.com/o/oauth2/token';
                $post_data = array(
                                'client_secret' =>   self::CLIENT_SECRET,
                                'grant_type'    =>   'refresh_token',
                                'refresh_token' =>   self::REFRESH_TOKEN,
                                'client_id'     =>   self::CLIENT_ID
                                );
                $ch = curl_init();
    
                curl_setopt($ch, CURLOPT_URL, $token_url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
                $result = curl_exec($ch);
                $token_object = json_decode($result);
    
                $cache_content['accessToken'] = $token_object->{'access_token'};
                $cache_content['accessTokenExpiry'] = time() + $token_object->{'expires_in'} - 60;
            }
    
            //---------------------------------------------------------------------
            // so now we have an access-token, let's use it to access the calendar
            $context = stream_context_create(array('http' => array('method' => "GET", 'header' => "Authorization: OAuth " . $cache_content['accessToken'])));
            
            // first let's retrieve the colors and cache them
            if (!isset($cache_content['calendarColors'])) {
                $resturl = 'https://www.googleapis.com/calendar/v3/colors';
                $content = @file_get_contents($resturl, false, $context);
                if ($content !== false)
                {
                    $result = json_decode($content,true);
                    $cache_content['calendarColors'] = $result["event"];
                    //var_dump($cache_content['calendarColors']);
                }
            }
    
            // then retrieve the users calendars available and cache them, too
            // do only if more than one calendar specified
            if (count($this->calendar_ids) > 1 && !isset($cache_content['calendarList'])) {
                $resturl = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
                $content = @file_get_contents($resturl, false, $context);
                if ($content !== false) {
                    $result = json_decode($content);
                    $calendarList = array();
    
                    foreach ($result->{'items'} as $entry) {
                        $cal = array();
                        $cal["description"]     = $entry->{'summary'};
                        $cal["backgroundColor"] = $entry->{'backgroundColor'};
                        $calendarList[$entry->{'id'}] = $cal;
                    }
    
                    $cache_content['calendarList'] = $calendarList;
                    //var_dump($cache_content['calendarList']);
                }
            }
            
            // retrieve the calendar entries from each calendar
            $events = array();
    
            foreach ($this->calendar_ids as $calendarid) {
                $resturl = 'https://www.googleapis.com/calendar/v3/calendars/'. urlencode($calendarid) . '/events?maxResults='. $this->count .'&q=-%22%40visu+no%22&singleEvents=true&orderBy=startTime&timeMin='.urlencode(date('c'));
                $content = @file_get_contents($resturl, false, $context);
                $this->debug($content);
    
                // for debugging purposes only
                // echo $content;
                // echo "###########";
    
                if ($content !== false)
                {
                    $result = json_decode($content,true);
    
                    foreach ($result["items"] as $entry)
                    {
                        $startstamp = (string)($entry["start"]["dateTime"]);
                        $endstamp = (string)($entry["end"]["dateTime"]);
                        if ($startstamp == '')
                            $startstamp = (string)($entry["start"]["date"]);
                        if ($endstamp == '')
                            $endstamp = (string)($entry["end"]["date"]);
                        $start = strtotime($startstamp);
                        $end   = strtotime($endstamp);
    
                        $color = '';
                        if (((string)($entry["colorId"]))!='') {
                            $color=$cache_content['calendarColors'][(string)($entry["colorId"])]['background'];
                        }
                        else if (count($this->calendar_ids) > 1) {
                            $color=$cache_content['calendarList'][$calendarid]['backgroundColor'];
                        }
    
                        $events[$start] = array(
                            'start' => date('y-m-d', $start).' '.date('H:i:s', $start),
                            'end' => date('y-m-d', $end).' '.date('H:i:s', $end),
                            'title' => (string)($entry["summary"]),
                            'content' => (string)($entry["description"]),
                            'where' => (string)($entry["location"]),
                            'color' => $color,
                            'link' => (string)($entry["htmlLink"])
                        );
                    }
                }
                else
                {
                    $this->error('Calendar: Google', 'Calendar '. $calendarid .' read request failed!');
                }
            }
    
            // finally re-order the events comming potentially from different calendars
            $i = 1;
            ksort($events);
            foreach($events as $event) {
                $event['pos'] = $i++;
                $this->data[] = $event;
                if ($i > $this->count) break;
            }
    
            // at the end write back cache
            $cache->write( json_encode($cache_content) );
        }
    }
    
    
    // -----------------------------------------------------------------------------
    // call the service
    // ----------------------------------------------------------------------------
    
    //
    
    $service = new calendar_google(array_merge($_GET, $_POST));
    echo $service->json();
    ?>

    Danke und Grüße,
    Lio



    Einen Kommentar schreiben:


  • lio123
    antwortet
    ;-) habe lediglich meine Daten hinzugefügt und überprüft, ob nichts versehentlich dazu oder weggekommen ist. Zuletzt habe ich Hendricks Code ausprobiert. Bringt aber immer noch den selben Fehler. Werde nun die ganze Prozedur wiederholen und hoffen dass es danach funktioniert.
    Gibt es eine weitere Möglichkeit zum debuggen?

    Danke und Grüße,
    Lio

    Einen Kommentar schreiben:


  • psilo
    antwortet
    lio123: ich meinte damit, dass du nicht selber drin rumeditiert hast

    Einen Kommentar schreiben:


  • henfri
    antwortet
    Hallo,

    so funktioniert es hier:
    Code:
    <?php
    /**
     * -----------------------------------------------------------------------------
     * @package     smartVISU
     * @author      Martin Gleiß (basic version), Carsten Gotschlich (google API V3), Thorsten Moll (cache, multiple calendars)
     * @copyright   2012
     * @license     GPL [http://www.gnu.de]
     * -----------------------------------------------------------------------------
     */
    
    // Note: for debugging purposes you can execute this script from commandline with    php -q <scriptname>
    
    require_once '../../../lib/includes.php';
    require_once const_path_system.'calendar/calendar.php';
    require_once const_path_system.'class_cache.php';
    
    /**
     * This class reads a google calendar
     */
    class calendar_google extends calendar
    {
        const CLIENT_ID     = '...............apps.googleusercontent.com';    // put your clientID here - from Google website
        const CLIENT_SECRET = '';    // put your client Secret here - from Google WebSitr
        const REFRESH_TOKEN = '';    // Put your google refresh token here - from other PHP script
    
        var $calendar_ids = array();
    
        /**
         * initialization of some parameters
         */
        public function init($request)
        {
            parent::init($request);
            if ($this->url == '')
                $this->url = 'primary';
            if ($this->count == 0)
                $this->count = 10;
    
            $this->calendar_ids = explode(',' , $this->url);
        }
    
    
        public function run()
        {
            $cache = new class_cache('calendar_google.json');
    
            // check for cached data
            if ($cache->hit(3600)) {
                $cache_content = json_decode($cache->read(), true);
    
                if ($cache_content['accessTokenExpiry'] < time()) {
                    // if token is not valid anymore reload everything cached
                    unset($cache_content);
                }
            }
    
            if (!isset($cache_content['accessToken'])) {
                $token_url = 'https://accounts.google.com/o/oauth2/token';
                $post_data = array(
                                'client_secret' =>   self::CLIENT_SECRET,
                                'grant_type'    =>   'refresh_token',
                                'refresh_token' =>   self::REFRESH_TOKEN,
                                'client_id'     =>   self::CLIENT_ID
                                );
                $ch = curl_init();
    
                curl_setopt($ch, CURLOPT_URL, $token_url);
                curl_setopt($ch, CURLOPT_POST, 1);
                curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
                $result = curl_exec($ch);
                $token_object = json_decode($result);
    
                $cache_content['accessToken'] = $token_object->{'access_token'};
                $cache_content['accessTokenExpiry'] = time() + $token_object->{'expires_in'} - 60;
            }
    
            //---------------------------------------------------------------------
            // so now we have an access-token, let's use it to access the calendar
            $context = stream_context_create(array('http' => array('method' => "GET", 'header' => "Authorization: OAuth " . $cache_content['accessToken'])));
            
            // first let's retrieve the colors and cache them
            if (!isset($cache_content['calendarColors'])) {
                $resturl = 'https://www.googleapis.com/calendar/v3/colors';
                $content = @file_get_contents($resturl, false, $context);
                if ($content !== false)
                {
                    $result = json_decode($content,true);
                    $cache_content['calendarColors'] = $result["event"];
                    //var_dump($cache_content['calendarColors']);
                }
            }
    
            // then retrieve the users calendars available and cache them, too
            // do only if more than one calendar specified
            if (count($this->calendar_ids) > 1 && !isset($cache_content['calendarList'])) {
                $resturl = 'https://www.googleapis.com/calendar/v3/users/me/calendarList';
                $content = @file_get_contents($resturl, false, $context);
                if ($content !== false) {
                    $result = json_decode($content);
                    $calendarList = array();
    
                    foreach ($result->{'items'} as $entry) {
                        $cal = array();
                        $cal["description"]     = $entry->{'summary'};
                        $cal["backgroundColor"] = $entry->{'backgroundColor'};
                        $calendarList[$entry->{'id'}] = $cal;
                    }
    
                    $cache_content['calendarList'] = $calendarList;
                    //var_dump($cache_content['calendarList']);
                }
            }
            
            // retrieve the calendar entries from each calendar
            $events = array();
    
            foreach ($this->calendar_ids as $calendarid) {
                $resturl = 'https://www.googleapis.com/calendar/v3/calendars/'. urlencode($calendarid) . '/events?maxResults='. $this->count .'&q=-%22%40visu+no%22&singleEvents=true&orderBy=startTime&timeMin='.urlencode(date('c'));
                $content = @file_get_contents($resturl, false, $context);
                $this->debug($content);
    
                // for debugging purposes only
                // echo $content;
                // echo "###########";
    
                if ($content !== false)
                {
                    $result = json_decode($content,true);
    
                    foreach ($result["items"] as $entry)
                    {
                        $startstamp = (string)($entry["start"]["dateTime"]);
                        $endstamp = (string)($entry["end"]["dateTime"]);
                        if ($startstamp == '')
                            $startstamp = (string)($entry["start"]["date"]);
                        if ($endstamp == '')
                            $endstamp = (string)($entry["end"]["date"]);
                        $start = strtotime($startstamp);
                        $end   = strtotime($endstamp);
    
                        $color = '';
                        if (((string)($entry["colorId"]))!='') {
                            $color=$cache_content['calendarColors'][(string)($entry["colorId"])]['background'];
                        }
                        else if (count($this->calendar_ids) > 1) {
                            $color=$cache_content['calendarList'][$calendarid]['backgroundColor'];
                        }
    
                        $events[$start] = array(
                            'start' => date('y-m-d', $start).' '.date('H:i:s', $start),
                            'end' => date('y-m-d', $end).' '.date('H:i:s', $end),
                            'title' => (string)($entry["summary"]),
                            'content' => (string)($entry["description"]),
                            'where' => (string)($entry["location"]),
                            'color' => $color,
                            'link' => (string)($entry["htmlLink"])
                        );
                    }
                }
                else
                {
                    $this->error('Calendar: Google', 'Calendar '. $calendarid .' read request failed!');
                }
            }
    
            // finally re-order the events comming potentially from different calendars
            $i = 1;
            ksort($events);
            foreach($events as $event) {
                $event['pos'] = $i++;
                $this->data[] = $event;
                if ($i > $this->count) break;
            }
    
            // at the end write back cache
            $cache->write( json_encode($cache_content) );
        }
    }
    
    
    // -----------------------------------------------------------------------------
    // call the service
    // ----------------------------------------------------------------------------
    
    //
    
    $service = new calendar_google(array_merge($_GET, $_POST));
    echo $service->json();
    ?>
    Gruß,
    Hendrik

    Einen Kommentar schreiben:


  • lio123
    antwortet
    Zitat von psilo Beitrag anzeigen
    .. einfach mal sicherstellen, dass das file das originalfile ist.
    Was meinst Du damit? Ich habe zuerst das letzte Script in diesem Beitrag genommen, das offensichtlich funktioniert (das mit den Erweiterungen). Danach habe ich das Script aus dem ersten Beitrag genommen, und zwar das, das als Code im Beitrag steht, nicht eines aus dem Anhang.

    Grüße,
    Lio

    Einen Kommentar schreiben:

Lädt...
X