我正在使用 Office 365 API 工具,我想获取登录的用户配置文件、电子邮件、姓名、...
我希望用户登录,然后我可以获得他的电子邮件地址。
这个怎么做?
我试过这个:
public static async Task<string> GetEmail()
{
var client = await EnsureClientCreated();
var x = await client.Me.ExecuteAsync();
return x.DisplayName;
}
public static async Task<ExchangeClient> EnsureClientCreated()
{
if (_discoveryContext == null)
{
_discoveryContext = await DiscoveryContext.CreateAsync();
}
var dcr = await _discoveryContext.DiscoverResourceAsync(ServiceResourceId);
_lastLoggedInUser = dcr.UserId;
return new ExchangeClient(ServiceEndpointUri, async () =>
{
return (await _discoveryContext.AuthenticationContext.AcquireTokenSilentAsync(ServiceResourceId, _discoveryContext.AppIdentity.ClientId, new Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier(dcr.UserId, Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifierType.UniqueId))).AccessToken;
});
}
但这仅获得显示名称,我也需要电子邮件。提前致谢。