Get user calendar using OutlookClient
Asked Answered
M

2

0

I'm using Outlook-SDK-Android (https://github.com/OfficeDev/Outlook-SDK-Android) to talk with Outlook Calendar REST API (https://msdn.microsoft.com/en-us/office/office365/api/calendar-rest-operations).

So far I've been able to get the events on my own calendar using:

            import com.microsoft.services.outlook.fetchers.OutlookClient;

            OutlookClient mClient;
            ...
            mClient = new OutlookClient(outlookBaseUrl, mResolver);
            ...
            mClient.getMe()                
                    .getCalendarView()
                    .addParameter("startDateTime", startDate)
                    .addParameter("endDateTime", endDate)
                    .read()

This corresponds to "https://outlook.office.com/api/v2.0/me/calendarView?startDateTime={start_datetime}&endDateTime={end_datetime}"

  • In order to use it for other users calendars on which I have read permission how do I achieve the same in the following format specified in the Outlook documentation?

"https://outlook.office.com/api/v2.0/USERS/[email protected]/calendars/Calendar/EVENTS?startDateTime={start_datetime}&endDateTime={end_datetime}"

(or also "..v2.0/USERS/[email protected]/CALENDARVIEW)

  • How do I add the query parameter "$select" to the latter, using OutlookClient? (eg. $select=Subject,Organizer,Start,End)
Melyndamem answered 23/2, 2016 at 18:17 Comment(0)
F
1

There is a select method:

public OrcCollectionFetcher<TEntity, TFetcher, TOperations> select(String select)

in OrcCollectionFetcher class, so you can call it like this:

mClient.getMe()                
                    .getCalendarView()
                    .addParameter("startDateTime", startDate)
                    .addParameter("endDateTime", endDate)
                    .select("Subject")
                    .read()

To get events from resource try this:

            final List<Event> events = outlookClient
                .getUsers()
                .getById("[email protected]")
                .getCalendarView()
                .addParameter("startDateTime", startDate)
                .addParameter("endDateTime", endDate)
                .read()
Fabio answered 8/3, 2016 at 18:35 Comment(8)
Thanks for your answer! :) Anyway my question was: 1) how to achieve something like getUser("[email protected]").getCalendarView().etc() and just after that 2) how to add the query parameter to the latterMelyndamem
Nice, it works! I receive back "> Error: "MyApp": Calendar error. Cause: Response status: 403 Response content: {"error":{"code":"ErrorAccessDenied","message":"Access is denied. Check credentials and try again."}}" but my understanding is that's just because I'm still using an account without permissions set for reading other accounts calendars.Melyndamem
I removed the check for accepted answer because it does not work. I've been provided an account with delegate access to the meeting rooms (with "author" permission level) but I'm still receiving back a 403. :(Melyndamem
Ga Sacchi: the problem you have (403) is with permissions and not with API usage. It works like a charm. Btw. have you considered using Graph API? This is the recommended way now to talk to MS services.Fabio
Don't know what do you mean by "deamon", I registered a server app (not native, nor web) added application permissions and works fine. From the first post I can see you develop for Android, that's the difference...Fabio
Yep a service app ("Build service and daemon apps in Office 365"). Feel free to leave comments with details about it on my other question. I'll probably do that too and call that service from my app. Is there a library that i can use on the service side to talk to the outlook api or just raw calls? Thanks againMelyndamem
@GaSacchi you can do both, there are plenty of technologies supported by Microsoft Graph Clients (see here: graph.microsoft.io/en-us/code-samples-and-sdks). Java is not mentioned here, but there is outdated (not working out of the box) Java client library for MS Graph: versioneye.com/java/com.microsoft.services:graph-services-java/… After few hacks, I made it work with current Graph API version (1.0).Fabio
Getting other users' data on which you have delegate access with Outlook REST API will work at the end of this month - see comment https://mcmap.net/q/673209/-office365-api-admin-accessing-another-users-room-39-s-calendar-eventsMelyndamem
L
0
        mClient.getMe()                
                .getCalendarView()
                .addParameter("startDateTime", startDate)
                .addParameter("endDateTime", endDate)
                .select("Subject,Start,End").
                .read()

See https://msdn.microsoft.com/office/office365/api/complex-types-for-mail-contacts-calendar#UseODataqueryparametersSelectspecificpropertiestobereturned

Litigate answered 18/5, 2016 at 4:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.