Fix for new version of api client.

This commit is contained in:
2019-07-28 11:37:39 +02:00
parent 5378daf278
commit 31fb0d3647
3 changed files with 18 additions and 19 deletions

View File

@@ -110,7 +110,7 @@ if ($bHasContactsCalendar) {
// Get contact id from event // Get contact id from event
$aPreferences = $oGadget->getPreferences(); $aPreferences = $oGadget->getPreferences();
if (!isset($aPreferences['goo.contactsContactId']) ) { if (!isset($aPreferences['goo.contactsContactId'])) {
continue; continue;
} }
$sContactId = $aPreferences['goo.contactsContactId']; $sContactId = $aPreferences['goo.contactsContactId'];
@@ -128,29 +128,28 @@ if ($bHasContactsCalendar) {
if (!isset($aContacts[$sContactId])) { if (!isset($aContacts[$sContactId])) {
// Get contact details from contact id // 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); $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); $oHttpClient = $oClient->authorize();
$oHttpRequest = $oAuth->sign($oHttpRequest); $oHttpRequest = new GuzzleHttp\Psr7\Request('GET', $sUrl);
$aResponse = $oClient->getIo()->executeRequest($oHttpRequest); $sResponse = $oHttpClient->send($oHttpRequest)->getBody()->getContents();
// Parse XML to fetch birthday // 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); $oXml = simplexml_load_string($sXml);
$aBirthday = (array) $oXml->birthday->attributes(); $sDate = ((array) $oXml->birthday)['@attributes']['when'];
$sDate = current(current($aBirthday));
// Save birthday date // Save birthday date
$aContacts[$sContactId][CALENDAR_BIRTHDAY_NAME] = $sDate; $aContacts[$sContactId][CALENDAR_BIRTHDAY_NAME] = $sDate;
// Iterate all events of contact // Iterate all events of contact
$aEvents = (array) $oXml->event; #$aEvents = (array) $oXml->event;
while (($oEvent = next($aEvents)) !== false) { #while (($oEvent = next($aEvents)) !== false) {
$aEvent = (array) $oEvent; # $aEvent = (array) $oEvent;
$sEvent = current(current($aEvent)); # $sEvent = current(current($aEvent));
$sDate = current(current(next($aEvent))); # $sDate = current(current(next($aEvent)));
#
// Save other event date # // Save other event date
$aContacts[$sContactId][$sEvent] = $sDate; # $aContacts[$sContactId][$sEvent] = $sDate;
} #}
} }
// Get date of current event // Get date of current event

View File

@@ -1,5 +1,5 @@
{ {
"require": { "require": {
"google/apiclient": "1.1.2" "google/apiclient": "2.2.3"
} }
} }

View File

@@ -5,7 +5,7 @@ define('CLIENT_SECRET', '');
define('REDIRECT_URI', sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'])); define('REDIRECT_URI', sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF']));
// Calendar preferences // 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('TARGET_CALENDAR_SUMMARY', 'Birthdays');
define('CALENDAR_BIRTHDAY_NAME', 'birthday'); define('CALENDAR_BIRTHDAY_NAME', 'birthday');
define('CONTACTS_USER_EMAIL', 'default'); define('CONTACTS_USER_EMAIL', 'default');