Google日历API重定向异常问题
本文关键字:异常 问题 重定向 API 日历 Google | 更新日期: 2023-09-27 17:58:56
我在访问谷歌日历时遇到了一个特殊的问题——有时它会生成"重定向异常",但大多数情况下它都很好。
我不知道如何重定向调用,从我搜索后读到的内容来看,它应该由谷歌的API处理,这对于调用函数来说是不可见的(但显然不是。)
该代码访问谷歌日历,获取所有辅助日历的列表以及每个日历的事件数。
API 1.8.0.0版(http://code.google.com/p/google-gdata/downloads/list)
错误消息:
Execution resulted in a redirect from https://www.google.com/calendar/feeds/tlf1juohv473hh0jhm046do5g9@group.calendar.google.com/private/full?gsessionid=MGsId0ULhyO_DkKlGa9DHw
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at GoogleDataTool.CalendarActions.GetSecondaryCalendars(Boolean IncludeEventCount, List`1& calendarlist) in D:'GoogleDataTool'classes'CalendarActions.cs:line 65
Response.Message: "Stream was not readable."
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.GDataGAuthRequest.Execute()
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
at Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince)
at Google.GData.Client.Service.Query(FeedQuery feedQuery)
at GoogleDataTool.CalendarActions.GetSecondaryCalendars(Boolean IncludeEventCount, List`1& calendarlist) in D:'GoogleDataTool'classes'CalendarActions.cs:line 84
at GoogleDataTool.Program.DoActions() in D:'GoogleDataTool'Program.cs:line 34
at GoogleDataTool.Program.Main(String[] args) in D:'GoogleDataTool'Program.cs:line 14
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
代码(它只收集集合中的日历、标题和事件计数):
public bool GetSecondaryCalendars(out List<CalendarData> calendarlist)
{
Console.WriteLine( "Starting calendarlist retrieval..." );
calendarlist = new List<CalendarData>();
CalendarService myService = new CalendarService( "Calendar-application" );
myService.setUserCredentials( "MyAccount@google.com", "MyPassword" );
CalendarQuery cQuery = new CalendarQuery();
cQuery.Uri = new Uri( "https://www.google.com/calendar/feeds/default/allcalendars/full" );
try
{
CalendarFeed cFeed = (CalendarFeed)myService.Query( cQuery );
foreach (CalendarEntry entry in cFeed.Entries)
{
// We don't want the primary calendar; just the secondary ones
if (!entry.Id.Uri.ToString().Contains( HttpUtility.UrlEncode( "MyAccount@google.com" ) ))
{
String calendarid = entry.Id.Uri.ToString().Substring( entry.Id.Uri.ToString().LastIndexOf( "/" ) + 1 );
calendarlist.Add( new CalendarData()
{
Text = entry.Title.Text,
Id = calendarid
} );
}
// Grab each calendar to count the number of events it has (not pretty, but I wish I could just ask the cFeed entries...)
foreach (CalendarData calendar in calendarlist)
{
FeedQuery query = new FeedQuery();
// Create the query object:
query.Uri = new Uri( string.Format( "https://www.google.com/calendar/feeds/{0}/private/full", calendar.Id ) );
// Tell the service to query:
AtomFeed calFeed = myService.Query( query );
calendar.EventCount = calFeed.Entries.Count;
}
}
}
catch (Exception ex)
{
Console.WriteLine( ex.Message );
return false;
}
return true;
}
public class CalendarData
{
public string Id { get; set; }
public string Text { get; set; }
public int EventCount { get; set; }
}
任何建议都非常受欢迎。
根据我的pov,你正在通过互联网工作-因此,你应该计划在放弃之前至少尝试两次;-)
因此,我会重试一次,然后引发一个对最终用户可见的实际异常。