I would like to understand if there is any API which can help us find the Office 365 user account information from my Excel add-in javascript code. Eg- Let's assume a user with Office email account abc@xyz.com launches Excel, downloads my add-in from Office store and uses it. I want to capture this user info from my app for the various users who downloaded/using my app. Is there an API in apps for office to achieve this?
问题:
回答1:
No, there is not currently an API in Office add-ins in Word/Excel/PowerPoint that exposes the user information for the person logged on to the Office clients.
In Outlook add-ins you can retrieve this information.
// Example: Allie Bellew
console.log(Office.context.mailbox.userProfile.displayName);
// Example: allieb@contoso.com
console.log(Office.context.mailbox.userProfile.emailAddress);
See the userProfile object documentation for more information.
回答2:
To add to Doug's response: while it doesn't expose the user's email address, you can get a unique identifier for the user from the entitlement token, provided your app is in the Office Store. See https://msdn.microsoft.com/en-us/library/office/jj164035.aspx for more info.
The UserId property of the entitlement token response (https://msdn.microsoft.com/en-us/library/office/verificationsvc.verifyentitlementtokenresponse_members.aspx) is the purchaser ID. Per the documentation above, "This is an encrypted value of the Microsoft account used by the person who purchased the app".
Hope this helps,
~ Michael Zlatkovsky, developer on Office Extensibility team, MSFT