131361
Oct 18, 2019
3249
3
0
Google Calendar API - Freebusy
Guten Morgen zusammen,
ich arbeite das erste mal mit der Google Calendar API und würde gerne via PHP die Information abfragen, an welchen Tagen ich wann einen Termin habe.
Dafür habe ich mir "Freebusy" angesehen - leider ist die Google Dokumentation nicht so PHP-freundlich, was mir die Sache erschwert.
Das habe ich bislang:
Die Antwort sieht so aus:
Leider ist das "Busy-Array" komplett leer.
Vermutlich, weil Google_Service_Calendar_Error einen "internalError" vorweist.
Leider hänge ich jetzt hier fest, da ich nicht weiß, wodurch der internalError zustande kommt :/
Hoffe ihr könnt helfen !
ich arbeite das erste mal mit der Google Calendar API und würde gerne via PHP die Information abfragen, an welchen Tagen ich wann einen Termin habe.
Dafür habe ich mir "Freebusy" angesehen - leider ist die Google Dokumentation nicht so PHP-freundlich, was mir die Sache erschwert.
Das habe ich bislang:
<?php
require_once 'vendor/autoload.php';
$client = new Google_Client();
$client->setScopes('https://www.googleapis.com/auth/calendar');
$client->addScope(Google_Service_Calendar::CALENDAR);
$client->setDeveloperKey("MEIN_API_KEY");
$cal = new Google_Service_Calendar($client);
$calendarId = 'primary';
$freebusy_req = new Google_Service_Calendar_FreeBusyRequest();
$freebusy_req->setTimeMin('2019-10-01T08:00:00.000-07:00');
$freebusy_req->setTimeMax('2019-10-31T10:00:00.000-07:00');
$freebusy_req->setTimeZone('Europe/Berlin');
$freebusy_req->setCalendarExpansionMax(10);
$freebusy_req->setGroupExpansionMax(10);
$item = new Google_Service_Calendar_FreeBusyRequestItem();
$item->setId($calendarId);
$freebusy_req->setItems(array($item));
$query = $cal->freebusy->query($freebusy_req);
$response_calendar = $query->getCalendars();
$busy_obj = $response_calendar[$calendarId]->getBusy();
echo '<pre>';
print_r($response_calendar);
echo '</pre>';
?>
Die Antwort sieht so aus:
Array
(
[primary] => Google_Service_Calendar_FreeBusyCalendar Object
(
[collection_key:protected] => errors
[busyType:protected] => Google_Service_Calendar_TimePeriod
[busyDataType:protected] => array
[errorsType:protected] => Google_Service_Calendar_Error
[errorsDataType:protected] => array
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
[errors] => Array
(
=> Google_Service_Calendar_Error Object
(
[domain] => global
[reason] => internalError
[internal_gapi_mappings:protected] => Array
(
)
[modelData:protected] => Array
(
)
[processed:protected] => Array
(
)
)
)
[busy] => Array
(
)
)
)
Leider ist das "Busy-Array" komplett leer.
Vermutlich, weil Google_Service_Calendar_Error einen "internalError" vorweist.
Leider hänge ich jetzt hier fest, da ich nicht weiß, wodurch der internalError zustande kommt :/
Hoffe ihr könnt helfen !
Please also mark the comments that contributed to the solution of the article
Content-Key: 506314
Url: https://administrator.de/contentid/506314
Printed on: April 27, 2024 at 02:04 o'clock
3 Comments
Latest comment
$freebusy_req = new Google_FreeBusyRequest();
$freebusy_req->setTimeMin(date(DateTime::ATOM, strtotime($date_from)));
$freebusy_req->setTimeMax(date(DateTime::ATOM, strtotime($date_to)));
$freebusy_req->setTimeZone('America/Chicago');
$item = new Google_FreeBusyRequestItem();
$item->setId('{calendarId}');
$freebusy_req->setItems(array($item));
$query = $service->freebusy->query($freebusy_req);