Open Vectrex opened 6 years ago
Did you find a solution since then?
I have a user who owns 4 calendars, but I don't find a way to list the events
Using @jamesiarmes answer, I have a user who is the owner of the calendars I need, then I use their .local address to list their meetings, I just need to loop over their address in this fashion:
// I'm using a wrapping class around, so $this->client represents the user mentionned above
$client = $this->client;
// $this->meetingRooms is a simple array: ["room1@company.local", "room2@company.local"]
foreach($this->meetingRooms as $meetingRoom) {
$folder_id = new DistinguishedFolderIdType();
$folder_id->Id = DistinguishedFolderIdNameType::CALENDAR;
$folder_id->Mailbox = new EmailAddressType();
// refreshing the Mailbox for current room iteration
$folder_id->Mailbox->EmailAddress = $meetingRoom;
$this->request->ParentFolderIds->DistinguishedFolderId[] = $folder_id;
$response = $client->FindItem($this->request);
$responses = $response->ResponseMessages->FindItemResponseMessage;
// method that wraps the final return response we see in the examples (the foreach part).
$this->print($responses);
}
And I get all the different meetings. Some few issues like some events being printed multiple times I need to investigate why.
I replaced James' library with Gareth's: https://github.com/Garethp/php-ews
There events and calendars are separate "things" and when retrieving events one doesn't need to know about calendars at all. (It took some time for me to figure out, that I don't retrieve calendars first and access the assigned events with these calendar items.) The code with garethp/php-ews looks like this:
$api = API::withUsernameAndPassword(
$host,
$username,
$password
[
'primarySmtpEmailAddress' => $emailAddressCalendarsGetSharedWith,
]
);
$items = $api->getCalendarItems(
(new \DateTime())->add(new \DateInterval('PT1S')),
(new \DateTime())->add(new \DateInterval('P1D')),
['ParentFolderIds' => [
'DistinguishedFolderId' => [
'id' => 'calendar',
'Mailbox' => [
'EmailAddress' => $email
]
]
]]
);
Since we moved on to shared mailboxes instead of public calendars, this also made me cry... We also use garethp php-ews and as of now the above code needs a bit of an adjustment. I go now with this:
$start = new \DateTime();
$end = clone $start;
$end->modify('+1 month');
$api = API::withUsernameAndPassword('owa.address', 'username', 'password', [
'timezone' => 'W. Europe Standard Time',
'version' => Enumeration\ExchangeVersionType::EXCHANGE_2013_SP1,
]);
$request = new API\Message\FindItemType();
$request->setParentFolderIds(new API\Type\NonEmptyArrayOfBaseFolderIdsType());
// Return all event properties.
$request->setItemShape(new API\Type\ItemResponseShapeType());
$request->getItemShape()->setBaseShape(Enumeration\DefaultShapeNamesType::ALL_PROPERTIES);
$folder_id = new API\Type\DistinguishedFolderIdType();
$folder_id->setId(Enumeration\DistinguishedFolderIdNameType::CALENDAR);
$folder_id->setMailbox(new API\Type\EmailAddressType());
$folder_id->getMailbox()->setEmailAddress('shmb_mailbox@organization.tld');
$request->getParentFolderIds()->setDistinguishedFolderId([$folder_id]);
$request->setCalendarView(new API\Type\CalendarViewType());
$request->getCalendarView()->setStartDate($start);
$request->getCalendarView()->setEndDate($end);
$response = $api->getClient()->FindItem($request);
$items = $response;
Problem (which seems super-simple, but I haven't found any feasible solution, yet): The Outlook web frontend shows both own calendars and all shared calendars. When accessing this account with php-ews I see my previously generated own events, but not the shared ones.
The code uses the
find.php
exampleYields
but no trace of any shared calendar events.
I suppose it must be simple - but so far I'm stuck.