我正在使用谷歌日曆api服務來訪問用戶日曆,它在我的本地工作正常,但它不能在服務器下工作是在我的本地工作正常的代碼。如何解決使用谷歌日曆api時發生的「一個或多個錯誤」問題
public ActionResult AddGoogleEvent()
{
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = clientid,
ClientSecret = clientsecret,
},
new[] { CalendarService.Scope.Calendar },
"user",
CancellationToken.None).Result;
var service = new CalendarService(new BaseClientService.Initializer(){
HttpClientInitializer = credential,
ApplicationName = "sampleappilication"
});
Google.Apis.Calendar.v3.Data.Event event1 = new Google.Apis.Calendar.v3.Data.Event()
{
Summary = "Appointment",
Location = location,
Start = new Google.Apis.Calendar.v3.Data.EventDateTime()
{
DateTime = new DateTime(Convert.ToInt32(yy), Convert.ToInt32(mn), Convert.ToInt32(dy), Convert.ToInt32(sthour), Convert.ToInt32(stminute), 0),
TimeZone = location
},
End = new Google.Apis.Calendar.v3.Data.EventDateTime()
{
DateTime = new DateTime(Convert.ToInt32(yy), Convert.ToInt32(mn), Convert.ToInt32(dy), Convert.ToInt32(ethour), Convert.ToInt32(etminute), 0),
TimeZone = "America/Los_Angeles"
},
Recurrence = new String[] {"RRULE:FREQ=WEEKLY;BYDAY=MO"},
Attendees = new List<Google.Apis.Calendar.v3.Data.EventAttendee>()
{
new Google.Apis.Calendar.v3.Data.EventAttendee() { Email = attendencess }
}
};
Google.Apis.Calendar.v3.Data.Event thisevent = service.Events.Insert(event1, "primary").Execute(); // Another error. "Does not contain a definition for Fetch"
string newEventID = thisevent.Id;
Session["Accepted"] = "Accepted";
return RedirectToAction("Eventconfirm");
}
異常
訪問路徑 'Google.Apis.Auth' 被拒絕。堆棧跟蹤:在 Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSu CCESS(Tasktask)自性rosoft.Runtime.Compi lerServices.TaskAwai ter.HandleNonSuccess(任務 任務)在 Google.Apis.Auth.OAuth2.GoogleWebAuthorizationBroker .d__1.MoveNe xt() in C:\ Users \ mdril \ Documents \ GitHub \ google-api-dotnet-client \ Src \ GoogleApis.Auth.Dot Net4 \ OAuth2 \ GoogleWe bAuthorizationBroker .cs:線 59來源:Microsoft.Threading.Tasks TargetSite:虛空 ThrowForNonSuccess(System.Threading.Tasks.Task)
任何一個可以建議如何解決這個問題
「不工作」非常模糊 - 到底發生了什麼問題,以及在哪裏? (我希望你有一個異常堆棧跟蹤...) –
是在檢查日誌文件時我收到以下異常。 發生一個或多個錯誤。 StackTrace:在System.Threading.Tasks.Task'1.GetResultCore(布爾waitCompletionNotification) at O365_APIs_Start_ASPNET_MVC.Controllers.ICalendarController。 d__104.MoveNext()in D:\ O365Calender_App_New \ O365Calender_App \ O365-APIs-Start-ASPNET -MVC \ \控制器ICalendarController。cs:line 4678 來源:mscorlib TargetSite:TResult GetResultCore(布爾型) --------------------------------- -------------------------- –
首先,這應該是在問題中,而不是在評論 - 然後,你應該找到*真實* InnerExceptions中的原始異常。如果沒有這些信息,它將非常難以幫助你。 –