Gabe
Gabe

Reputation: 6347

Outlook REST API - Get logged in user's email address

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:

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

Upvotes: 1

Views: 2729

Answers (2)

Gabe
Gabe

Reputation: 6347

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());
    }
});

Upvotes: 1

Fei Xue
Fei Xue

Reputation: 14649

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

Upvotes: 4

Related Questions