Google日历API错误405

本文关键字:错误 API 日历 Google | 更新日期: 2023-09-27 18:26:54

我在这个示例代码中尝试Google Calendar API,但我得到了以下错误:

Execution of authentication request returned unexpected result: 405
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: Google.GData.Client.GDataRequestException: Execution of authentication request returned unexpected result: 405

堆栈跟踪:

堆栈跟踪:

[GDataRequestException:返回身份验证请求的执行意外结果:405]
_2.C:''Users''Samsung''Desktop''Development''Ticketing中的BusinessLogicLayer.LogicClasses.LeaveLogic.AddToGoogleCalendar()system''2.BusinessLogicLayer''LogicClasses''LeaveLogic.cs:375
_1.PresentationLayer.WebPages.LeaveRequest.tstbtn_Click(Object sender,EventArgs e)在C:''Users''Samsung''Desktop''Development''Ticketing中system''1.PresentationLayer''WebPages''LeaveRequest.aspx cs:403
System.Web.UI.WebControls.Button.OnClick(EventArgs e)+9553594
System.Web.UI.WebControls.Button.RisePostBackEvent(字符串eventArgument)+103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串eventArgument)+10
System.Web.UI.Page.RisePostBackEvent(IPostBackEventHandlersourceControl,String eventArgument)+13
System.Web.UI.Page.RisePostBackEvent(NameValueCollection postData)+35 System.Web.UI.Page.ProcessRequestMain(布尔值包括同步点之前的阶段,布尔值包括异步点之后的阶段)+1724

代码:

string sGoogleUserName = "******@gmail.com";
            string sGooglePassword = "*****";
            Uri oCalendarUri = new Uri("http://www.google.com/calendar/feeds/" + sGoogleUserName + "/private/full");
            //Initialize Calendar Service
            CalendarService oCalendarService = new CalendarService("CalendarSampleApp");
            oCalendarService.setUserCredentials(sGoogleUserName, sGooglePassword);
            //Use Proxy 
            GDataRequestFactory oRequestFactory = (GDataRequestFactory)oCalendarService.RequestFactory;
            WebProxy oWebProxy = new WebProxy(WebRequest.DefaultWebProxy.GetProxy(oCalendarUri));
            oWebProxy.Credentials = CredentialCache.DefaultCredentials;
            oWebProxy.UseDefaultCredentials = true;
            oRequestFactory.Proxy = oWebProxy;

            //Set Event Entry 
            EventEntry oEventEntry = new EventEntry();
            oEventEntry.Title.Text = "Test Calendar Entry From .Net";
            oEventEntry.Content.Content = "Hurrah!!! I posted my first Google calendar event through .Net";
            //Set Event Location 
            Where oEventLocation = new Where();
            oEventLocation.ValueString = "New Zealand";
            oEventEntry.Locations.Add(oEventLocation);
            //Set Event Time
            When oEventTime = new When(new DateTime(2011, 5, 31, 9, 0, 0), new DateTime(2011, 5, 31, 9, 0, 0).AddHours(1));
            oEventEntry.Times.Add(oEventTime);
            //Set Additional Properties
            ExtendedProperty oExtendedProperty = new ExtendedProperty();
            oExtendedProperty.Name = "SynchronizationID";
            oExtendedProperty.Value = Guid.NewGuid().ToString();
            oEventEntry.ExtensionElements.Add(oExtendedProperty);
            // CalendarService oCalendarService = GAuthenticate();
            //Prevents This Error
            //{"The remote server returned an error: (417) Expectation failed."}
            System.Net.ServicePointManager.Expect100Continue = false;
            //Save Event
            oCalendarService.Insert(oCalendarUri, oEventEntry);

Google日历API错误405

注释它应该工作的代理部分:

////Use Proxy 
//GDataRequestFactory oRequestFactory = (GDataRequestFactory)oCalendarService.RequestFactory;
//WebProxy oWebProxy = new WebProxy(WebRequest.DefaultWebProxy.GetProxy(oCalendarUri));
//oWebProxy.Credentials = CredentialCache.DefaultCredentials; //oWebProxy.UseDefaultCredentials = true;
//oRequestFactory.Proxy = oWebProxy;