From 31fb0d36477271bb02ca51edda96889950a5b909 Mon Sep 17 00:00:00 2001 From: Rik Veenboer Date: Sun, 28 Jul 2019 11:37:39 +0200 Subject: [PATCH] Fix for new version of api client. --- calendar.php | 33 ++++++++++++++++----------------- composer.json | 2 +- settings.php | 2 +- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/calendar.php b/calendar.php index 25bbad4..0a99367 100644 --- a/calendar.php +++ b/calendar.php @@ -110,7 +110,7 @@ if ($bHasContactsCalendar) { // Get contact id from event $aPreferences = $oGadget->getPreferences(); - if (!isset($aPreferences['goo.contactsContactId']) ) { + if (!isset($aPreferences['goo.contactsContactId'])) { continue; } $sContactId = $aPreferences['goo.contactsContactId']; @@ -128,29 +128,28 @@ if ($bHasContactsCalendar) { if (!isset($aContacts[$sContactId])) { // Get contact details from contact id $sUrl = sprintf('https://www.google.com/m8/feeds/contacts/%s/full/%s?v=3.0', CONTACTS_USER_EMAIL, $sContactId); - $oHttpRequest = new Google_Http_Request($sUrl); - $oHttpRequest = $oAuth->sign($oHttpRequest); - $aResponse = $oClient->getIo()->executeRequest($oHttpRequest); - + $oHttpClient = $oClient->authorize(); + $oHttpRequest = new GuzzleHttp\Psr7\Request('GET', $sUrl); + $sResponse = $oHttpClient->send($oHttpRequest)->getBody()->getContents(); + // Parse XML to fetch birthday - $sXml = str_replace(array('gd:', 'gContact:'), null, $aResponse[0]); + $sXml = str_replace(array('gd:', 'gContact:'), null, $sResponse); $oXml = simplexml_load_string($sXml); - $aBirthday = (array) $oXml->birthday->attributes(); - $sDate = current(current($aBirthday)); + $sDate = ((array) $oXml->birthday)['@attributes']['when']; // Save birthday date $aContacts[$sContactId][CALENDAR_BIRTHDAY_NAME] = $sDate; // Iterate all events of contact - $aEvents = (array) $oXml->event; - while (($oEvent = next($aEvents)) !== false) { - $aEvent = (array) $oEvent; - $sEvent = current(current($aEvent)); - $sDate = current(current(next($aEvent))); - - // Save other event date - $aContacts[$sContactId][$sEvent] = $sDate; - } + #$aEvents = (array) $oXml->event; + #while (($oEvent = next($aEvents)) !== false) { + # $aEvent = (array) $oEvent; + # $sEvent = current(current($aEvent)); + # $sDate = current(current(next($aEvent))); + # + # // Save other event date + # $aContacts[$sContactId][$sEvent] = $sDate; + #} } // Get date of current event diff --git a/composer.json b/composer.json index a72b68f..c2e84f3 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { "require": { - "google/apiclient": "1.1.2" + "google/apiclient": "2.2.3" } } \ No newline at end of file diff --git a/settings.php b/settings.php index f2f43e3..adedd51 100644 --- a/settings.php +++ b/settings.php @@ -5,7 +5,7 @@ define('CLIENT_SECRET', ''); define('REDIRECT_URI', sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'])); // Calendar preferences -define('CONTACTS_CALENDAR_ID', '#contacts@group.v.calendar.google.com'); +define('CONTACTS_CALENDAR_ID', 'addressbook#contacts@group.v.calendar.google.com'); define('TARGET_CALENDAR_SUMMARY', 'Birthdays'); define('CALENDAR_BIRTHDAY_NAME', 'birthday'); define('CONTACTS_USER_EMAIL', 'default');