0

I'm developing an Android App that will manage bookings for a few Outlook meeting rooms (users). The idea is just to display their availability and book a room for a certain amount of time.

So far I have had success getting the events just on my own calendar using Outlook SDK Android.

// logon() {
       ...
       mResolver = new DependencyResolver.Builder(
              new OkHttpTransport().setInterceptor(new LoggingInterceptor()),  
              new GsonSerializer(),
              new AuthenticationCredentials() {
                   @Override
                   public Credentials getCredentials() {
                      return new OAuthCredentials(
                                   authenticationResult.getAccessToken()
                      );
                   }
              }).build();


// onCreate() {

      Futures.addCallback( logon(), new FutureCallback<Boolean>() { 
            @Override
            public void onSuccess(Boolean result) {
                mClient = new OutlookClient(outlookBaseUrl, mResolver);
                getCalendars();
            }

            @Override
            public void onFailure(Throwable t) {
                Log.e("logon", t.getMessage());
            }
      });


      ...

      protected void getCalendars() {
          DateTime startDate = new DateTime(   
              DateTime.parse("2016-02-05T00:00:00Z"));
          DateTime endDate = new DateTime(
              DateTime.parse("2016-02-06T00:00:00Z"));
          Futures.addCallback(
              mClient.getMe()
                      .getCalendarView()
                      .addParameter("startDateTime", startDate)
                      .addParameter("endDateTime", endDate)
                      .read(),

              new FutureCallback<OrcList<Event>>() {
                  @Override
                  public void onSuccess(final OrcList<Event> result) {
                      runOnUiThread(new Runnable() {
                          @Override
                          public void run() {
                              StringBuilder sb = new StringBuilder();
                              ListIterator<Event> events =
                                          result.listIterator();
                              while (events.hasNext()) {
                                  Event event = events.next();
                                  sb.append(event.getSubject() + "\n");
                              }
                              messagesTextView.setText(sb.toString());
                          }
                      });
                  }

                  @Override
                  public void onFailure(Throwable t) {
                      Log.e("Calendar error", t.getLocalizedMessage());
                  }
              }
          );
      }    

Or in alternative using getUsers() instead of getMe(): see here.

So now next steps are:

  1. Do I need an admin user even just to read the meeting rooms calendar or there's some other way?

  2. If I won't be allowed to use an admin account can I manage multiple users with a good usability / performance relying on Oauth flow?

  3. I'm new to Android, is it easier to deal with Outlook REST API or Microsoft Graph?

Thanks

Community
  • 1
  • 1
Gabe
  • 5,997
  • 5
  • 46
  • 92

2 Answers2

1
  1. Today you need to use client credentials flow (AppOnly) if you want your app to access other user's calendar. We are working on an API that will allow to get availability information, more details soon.

  2. Using the OAuth flow you get an access token and a refresh token, the access token is valid for a short period of time and the refresh token can be used to generate new access tokens. The tokens are per user, you basically store the refresh tokens in your app on a per user cache.

  3. From the platform perspective it is the same to interact with the individual Outlook endpoint or the Microsoft Graph. If you app wants to access more than calendar information, like user profile or files, then using Microsoft Graph is the recommendation as you can access data from multiple services under a single endpoint and with a single access token.

Yina - MSFT
  • 1,756
  • 1
  • 12
  • 10
  • Thank you. One more thing about point 2: The app will fetch updated data at least every 30 seconds but since it will automatically stop working during night time I need to get a new access token every morning at start up of the app, right? Do I need to store all user credentials to be sure to be able to be always logged in? New question:http://stackoverflow.com/questions/35353319/oauth-grant-flow-tokens-expiration. TA again – Gabe Feb 12 '16 at 14:48
  • 1
    You don't need to store user credentials, actually we advise against doing this. What you store is the refresh token. Using the refresh token you can go back to the token endpoint and request a new access token – Yina - MSFT Feb 13 '16 at 00:53
  • With client credentials flow you mean using a service/daemon app? (https://msdn.microsoft.com/en-us/library/azure/dn645543.aspx) Is it the only way? I've been provided an account with delegate access to the meeting rooms (with "author" permission level) but I'm receiving back 403. :( – Gabe Mar 13 '16 at 21:52
1

You need an admin account just to setup the application in Azure. After you set the right Application Permissions you will not need the admin account if you use the app only authorization.

Outlook REST API gives only the current user's information however with Graph API, You can get any meeting room's or any user's events just by sending a request to

https://graph.microsoft.com/v1.0/users/<meetingroom/user email>/calendarView/?endDateTime=2015-12-28T22:23:00Z&startDateTime=2015-12-28T00:00:00Z

Please note that the date format should be in ISO 8601 format.

Hope it helps.

Onur Kucukkece
  • 1,708
  • 1
  • 20
  • 46
  • I registered the app using Outlook work account, worked fine. I think I can achieve the same using Calendar API. I tried this using Outlook Oauth sandbox (https://oauthplay.azurewebsites.net/) : GET https://outlook.office.com/api/v2.0/users/ameetinroom@etc.com/calendar but I got 403 - "The token contains not enough scope to make this delegate access call". So the problem is just permissions.. – Gabe Feb 12 '16 at 13:22
  • He doesn't seem to agree about graph: http://stackoverflow.com/questions/34858409/office-365-rest-api-access-meeting-rooms-calendars?rq=1 Thanks – Gabe Feb 12 '16 at 14:43
  • 1
    There is a statement like 'as the Outlook REST API requests are always performed on behalf of the current user.' in the target user section in the following page https://msdn.microsoft.com/office/office365/api/use-outlook-rest-api. Can it be something related to this? – Onur Kucukkece Mar 27 '16 at 20:36