Outlook - Read another user's calendar
Asked Answered
T

2

8

I'm developing an Android App based on Outlook-SDK-Android. The App talks with Outlook Calendar REST API to retrieve, book and delete events (see code examples here and here). Now I need to read someone else's calendar and I've been provided an Office365 account with delegate access (author permission level) towards other users.

I've registered my app using the provided account on the new portal. In my App I use the scope "https://outlook.office.com/Calendars.ReadWrite". (The scope is used in com.microsoft.aad.adal.AuthenticationContext.acquireToken() to initialize an Office REST Client for Android OutlookClient, a shared client stack provided by orc-for-android)

When I try to read another user's calendar on which I have delegate access I just receive back a 403 response:

{
  "error": {
    "code": "ErrorAccessDenied",
    "message": "Access is denied. Check credentials and try again."
  }
}

Any help?

Is it a limitation of the API? If so why is the following method invocation chain provided then?

outlookClient.getUsers()
             .getById("[email protected]")
             .getCalendarView()

UPDATE:

It seems like there are works in progress that will allow this scenario, as reported here: Office 365 REST API - Access meeting rooms calendars

So if progress in that direction has been made can I achieve my goal without using an "admin service app"? (see Office 365 API or Azure AD Graph API - Get Someone Elses Calendar)

Can I use basic authentication as suggested here?

Tester answered 13/3, 2016 at 22:16 Comment(0)
E
4

Calendar delegation is a feature of Exchange, the Graph API and Outlook API do not allow the user to access the delegated calendar. Currently, the alternative workaround could be use the EWS. And here is an sample for your reference:

static void DelegateAccessSearchWithFilter(ExchangeService service, SearchFilter filter)
{
    // Limit the result set to 10 items.
    ItemView view = new ItemView(10);

    view.PropertySet = new PropertySet(ItemSchema.Subject,
                                       ItemSchema.DateTimeReceived,
                                       EmailMessageSchema.IsRead);

    // Item searches do not support deep traversal.
    view.Traversal = ItemTraversal.Shallow;

    // Define the sort order.
    view.OrderBy.Add(ItemSchema.DateTimeReceived, SortDirection.Descending);

    try
    {
        // Call FindItems to find matching calendar items. 
        // The FindItems parameters must denote the mailbox owner,
        // mailbox, and Calendar folder.
        // This method call results in a FindItem call to EWS.
        FindItemsResults<Item> results = service.FindItems(
        new FolderId(WellKnownFolderName.Calendar,
            "[email protected]"),
            filter,
            view);

        foreach (Item item in results.Items)
        {
            Console.WriteLine("Subject: {0}", item.Subject);
            Console.WriteLine("Id: {0}", item.Id.ToString());
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Exception while enumerating results: { 0}", ex.Message);
    }
}

private static void GetDeligateCalendar(string mailAddress, string password)
{
    ExchangeService service = new ExchangeService();

    service.Credentials = new WebCredentials(mailAddress, password);

    service.TraceEnabled = true;
    service.TraceFlags = TraceFlags.All;

    service.AutodiscoverUrl(mailAddress, RedirectionUrlValidationCallback);

    SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(AppointmentSchema.Subject, "Discuss the Calendar REST API"));
    DelegateAccessSearchWithFilter(service, sf);
}

And if you want the Outlook and Graph API to support this feature, you can try to contact the Office developer team from link below:

https://officespdev.uservoice.com/

Ev answered 15/3, 2016 at 12:12 Comment(5)
Is EWS for Android reliable/stable? (github.com/faisons/EWS-For-Android , github.com/OfficeDev/ews-java-api ) ThanksTester
I too think EWS is the way to go here. In reality, the O365 API is really just a wrapper on top of EWS so there should be no loss in stability/functionality. Here's some more info on EWS delegate access: msdn.microsoft.com/en-us/library/office/…Tret
@Fei Xue Do you think Graph API could have solved the problem? See.. #34474329 - ThanksTester
@GaSacchi It should be able to get the others' calendar by using the calendarView REST. However it require the app-only token. Based on the orignal post, it seems you were using the user-level token.Ev
It seems like delegate access for Outlook API will be available at the end of this month - See answer to comment.. https://mcmap.net/q/673209/-office365-api-admin-accessing-another-users-room-39-s-calendar-eventsTester
S
1

FindMeetingTimes is currently in preview! To view the details, use this link and then change it to view the Beta version of the article (top right in the main column): https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations#Findmeetingtimespreview

Details below from the article, but please use the link to get the latest:

Find meeting times (preview)

Find meeting time suggestions based on organizer and attendee availability, and time or location constraints.

This operation is currently in preview and available in only the beta version.

All the supported scenarios use the FindMeetingTimes action. FindMeetingTimes accepts constraints specified as parameters in the request body, and checks the free/busy status in the primary calendars of the organizer and attendees. The response includes meeting time suggestions, each of which is defined as a MeetingTimeCandidate, with attendees having on the average a confidence level of 50% chance or higher to attend.

Salon answered 22/3, 2016 at 20:45 Comment(1)
FindMeetingTimes does not allow me to get other users meeting but just available times. Thanks, useful anywayTester

© 2022 - 2024 — McMap. All rights reserved.