1

How do I get the logged in user's email address using Outlook REST API?

I'm using com.microsoft.services.outlook.fetchers.OutlookClient (https://github.com/OfficeDev/Office-365-SDK-for-Java/blob/master/sdk/outlook-services/src/main/java/com/microsoft/services/outlook/fetchers/OutlookClient.java).

Is extracting it from the JWT access token the only way (see here and here) ? (Latest changes to tokens here)

Thanks

UPDATE: Following this approach:

  • Get the Inbox parent folder ID:

    mClient.getMe().getMailFolders().getById("Inbox").read()

    inboxMailFolderResult.getParentFolderId()

  • Get the parent folder display name using the ID retrieved

    mClient.getMe().getMailFolders().getById("ID_RETRIEVED_AAA==").read()

    parentMailFolderResult.getDisplayName()

..doesn't seem to work either, I just get Top of Information Store as display name.

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

2 Answers2

4

The Office 365 SDK for Java only provide the Outlook service at present. We can also get the email address of the sign-in user through the metadata via making the REST directly. Here is the REST request for your reference:

GET: https://outlook.office.com/api/v2.0/me
authorization: bearer {Token}

You would get the response like below: enter image description here

Fei Xue
  • 14,369
  • 1
  • 19
  • 27
  • Thanks, that's the info I needed. So a simple `mClient.getMe().read()` will work for me. +1 – Gabe Jun 13 '16 at 11:19
  • There's no way to fetch email aliases also associated with the account is there? – jwg2s Sep 08 '17 at 17:38
1

Following FeiXue's answer this is the code needed:

Futures.addCallback(mClient.getMe().read(), new FutureCallback<User>() {
    @Override
    public void onSuccess(User result) {
        Log.d("APP", "Logged in user's email address: "+result.getEmailAddress());
    }

    @Override
    public void onFailure(@NonNull Throwable t) {
        Log.e("Email fetch failure. Cause:", t.getMessage());
    }
});
Gabe
  • 5,997
  • 5
  • 46
  • 92