我在这里使用这个样本:
public async Task<ActionResult> Index()
{
var eventsResults = new List<MyEvent>();
var accessToken = await GetGraphAccessTokenAsync();
try
{
var graphService = GetGraphServiceClient(accessToken);
var request = graphService.Me.Events.Request(new Option[] { new QueryOption("top", "20"), new QueryOption("skip", "0") });
var userEventsCollectionPage = await request.GetAsync();
foreach (var evnt in userEventsCollectionPage)
{
eventsResults.Add(new MyEvent
{
Subject = !string.IsNullOrEmpty(evnt.Subject) ? evnt.Subject : string.Empty,
Start = !string.IsNullOrEmpty(evnt.Start.DateTime) ? DateTime.Parse(evnt.Start.DateTime) : new DateTime(),
End = !string.IsNullOrEmpty(evnt.End.DateTime) ? DateTime.Parse(evnt.End.DateTime) : new DateTime()
});
}
}
catch (Exception el)
{
el.ToString();
}
ViewBag.Events = eventsResults.OrderBy(c => c.Start);
return View();
}
然而我得到了错误
Failed to acquire token silently. Call method AcquireToken
Descripción: Excepción no controlada al ejecutar la solicitud Web actual. Revise el seguimiento de la pila para obtener más información acerca del error y dónde se originó en el código.
Detalles de la excepción: Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException: Failed to acquire token silently. Call method AcquireToken
Error de código fuente:
Línea 60: // create auth context
Línea 61: AuthenticationContext authContext = new AuthenticationContext(SettingsHelper.AzureAdAuthority, new ADALTokenCache(signInUserId));
Línea 62: var result = await authContext.AcquireTokenSilentAsync(SettingsHelper.AzureAdGraphResourceURL, clientCredential, userIdentifier);
Línea 63:
Línea 64: return result.AccessToken
谢谢