ja in der config, per page. obs das jetzt ist glaube ich nicht. bei dir sieht es aus wie wenn er entweder 2mal einen header senden will oder irgendwo eine debugausgabe reinkreuzt.. einfach mal sicherstellen, dass das file das originalfile ist.
Ankündigung
Einklappen
Keine Ankündigung bisher.
Google Calendar - update für "neue" GoogleAPI
Einklappen
X
-
Hallo,
Habe in der Konfiguration mehrere Kalender angegeben (meiner, Frau, Feiertage). Soweit alles super. Jetzt ist mir aufgefallen wenn ich in meinem Kalendar einen ganztägigen Termin eintrage, z.b. Urlaub, Geburtstag, wird mir dieser in der Visu nicht angezeigt. Ändere ich den Termin z.b. auf 00:00 bis 23:59 ist er plötzlich sichtbar. Dies gilt auch für Termine über mehrere Tage.
Ist dies sonst noch jemanden aufgefallen?
Kommentar
-
Zitat von psilo Beitrag anzeigen.. einfach mal sicherstellen, dass das file das originalfile ist.
Grüße,
Lio
Kommentar
-
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(); ?>
Hendrik
Kommentar
-
;-) 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
Kommentar
-
habe nochmal alles frisch gemacht und kommt immer noch
Code:[{"title":"Calendar: Google","text":"Calendar primary read request failed!"}]
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
Kommentar
-
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.
Kommentar
-
Zitat von ponG Beitrag anzeigenHallo 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ß,
SaschaCode:urn:ietf:wg:oauth:2.0:oob
Kommentar
Kommentar