我正在尝试从ASP.NET MVC C#Web应用程序运行Google Calendar API。当我在这种模式下进行调试时,代码会挂起credential = GoogleWebAuthorizationBroker.AuthorizeAsync
,我假设它正在尝试工作并超时,但我没有从浏览器或Visual Studio收到任何反馈
public void AddEventToCalendar(ConcertModel concert)
{
var scope = new[] {CalendarService.Scope.Calendar};
UserCredential credential;
var fileName = @"G:\\Source\\Hudl\\Hudl\\Hudl\\Content\\client_secrets.json";
using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scope, "user", CancellationToken.None,
new FileDataStore("Calendar.Vb.Sample")).Result;
}
var initializer = new BaseClientService.Initializer();
initializer.HttpClientInitializer = credential;
initializer.ApplicationName = "VB.NET Calendar Sample";
_service = new CalendarService(initializer);
IList<CalendarListEntry> list = _service.CalendarList.List().Execute().Items;
DisplayList(list);
foreach (var calendar in list)
{
DisplayFirstCalendarEvents(calendar);
}
}
我使用的是测试版Microsoft.Bcl.Async v1.0.166在.NET 4.0中运行