try
{
ClientCredential clientCredential = new ClientCredential("***********","**************");
UserIdentifier userIdentifier = new UserIdentifier(userObjectId, UserIdentifierType.UniqueId);
DiscoveryClient discClient = new DiscoveryClient(SettingsHelper.DiscoveryServiceEndpointUri,
async () =>
{
var authResult = await authContext.AcquireTokenSilentAsync(SettingsHelper.DiscoveryServiceResourceId,
clientCredential, userIdentifier);
return authResult.AccessToken;
});
var dcr = await discClient.DiscoverCapabilityAsync(capabilityName);
return new OutlookServicesClient(dcr.ServiceEndpointUri,
async () =>
{
var authResult = await authContext.AcquireTokenSilentAsync(dcr.ServiceResourceId, clientCredential, userIdentifier);
return authResult.AccessToken;
});
}
catch (AdalException exception)
{
//Handle token acquisition failure
if (exception.ErrorCode == AdalError.FailedToAcquireTokenSilently)
{
authContext.TokenCache.Clear();
throw exception;
}
return null;
}给出错误“未能默默地获取令牌。请调用方法AcquireToken”
发布于 2016-04-20 11:23:04
请确保应用程序是在Office 365租户AD下注册的,否则您将无法发现和使用Office 365服务。
Step#1下载示例项目AspNetMvc-with-O365.zip。
Step#2在Office365TenerAD下注册一个应用程序,声明Office365ExchangeOnline> Read用户邮件权限,并将应答URL设置为"http://localhost:2659/“。

Step#3在web.config文件中,从Azure门户复制ClientId、TenantId和客户端机密。

Step#4在Visual中运行项目并使用Azure帐户登录
预期结果如下:

如果您有令牌问题,也可以单击“清除缓存数据库”按钮。
https://stackoverflow.com/questions/36708812
复制相似问题