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

为君一笑 提交于 2019-12-24 16:42:59

问题


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.


回答1:


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:




回答2:


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


来源:https://stackoverflow.com/questions/37768014/outlook-rest-api-get-logged-in-users-email-address

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!