0

我正在开发 mvc 4 Web 应用程序。我想实现一个功能,其中场景如下 - 将有 gmail id 作为输入:abc@gmail.com。当用户输入此内容时,应用程序应获取相应电子邮件 ID 的所有日历事件并显示它们。

我经历过这个-

http://msdn.microsoft.com/en-us/library/live/hh826523.aspx#cal_rest

https://developers.google.com/google-apps/calendar/v2/developers_guide_protocol

我是新手,我搜索了很多但没有任何解决方案。请帮忙!提前致谢!

4

2 回答 2

1

得到了解决方案。只参考这个。

https://github.com/nanovazquez/google-calendar-sample

于 2013-06-06T13:08:07.033 回答
0

请检查以下步骤。

  1. 添加谷歌数据 API SDK。
  2. 试试这段代码。我为一个项目编写了这段代码,但我删除了一些与谷歌日历无关的代码。如果您不想使用 SDK,您可以简单地根据规范对您的日历链接执行 http-get 或 http-post。

            CalendarService service = new CalendarService("A.Name");
            const string GOOGLE_CALENDAR_FEED = "https://www.google.com/calendar/feeds/";
            const string GOOGLE_CALENDAR_DEFAULT_ALL_CALENDAR_FULL = "default/allcalendars/full";
            const string GOOGLE_CALENDAR_ALL_PRIVATE_FULL = "private/full";
    
            private void SetUserCredentials() {
                var userName = ConfigurationManager.AppSettings["GoogleUserName"];
                var passWord = Security.DecryptString(ConfigurationManager.AppSettings["GooglePasswrod"]).ToInsecureString();
                if (userName != null && userName.Length > 0) {
                    service.setUserCredentials(userName, passWord);
                }
            }        
    
            private CalendarFeed GetCalendarsFeed() {
                CalendarQuery calendarQuery = new CalendarQuery();
                calendarQuery.Uri = new Uri(GOOGLE_CALENDAR_FEED + GOOGLE_CALENDAR_DEFAULT_ALL_CALENDAR_FULL);
    
                CalendarFeed resultFeed = (CalendarFeed)service.Query(calendarQuery);
                return resultFeed;
            }
    
        private TherapistTimeSlots GetTimeSlots(CalendarEntry entry2) {
    
    
        string feedstring = entry2.Id.AbsoluteUri.Substring(63);
        var postUristring = string.Format("{0}{1}/{2}", GOOGLE_CALENDAR_FEED, feedstring, GOOGLE_CALENDAR_ALL_PRIVATE_FULL);
    
        EventFeed eventFeed = GetEventFeed(postUristring);
        slot.Events = new List<Event>();
    
        if (eventFeed != null) {
            var orderEventList = (from entity in eventFeed.Entries
                                  from timeslot in ((EventEntry)entity).Times
                                  orderby timeslot.StartTime
                                  select entity).ToList();
    
        }
        return slot;
    }
    
    private EventFeed GetEventFeed(string postUristring) {
    
        var eventQuery = new EventQuery();
        eventQuery.Uri = new Uri(postUristring);
        var h = Convert.ToInt32(DateTime.Now.ToString("HH", System.Globalization.DateTimeFormatInfo.InvariantInfo));
        eventQuery.StartTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, h, 0, 0);
        eventQuery.EndTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, h + 2, 0, 0);
        try {
            EventFeed eventFeed = service.Query(eventQuery) as EventFeed;
            return eventFeed;
        }
        catch (Exception ex) {
            /*
             * http://groups.google.com/group/google-calendar-help-dataapi/browse_thread/thread/1c1309d9e6bd9be7
             * 
             *  Unfortunately, the calendar API will always issue a redirect to give you a 
                gsessionid that will optimize your subsequent requests on our servers. 
                Using the GData client library should be transparent for you as it is taking 
                care of handling those redirect; but there might some times where this error 
                occurs as you may have noticed. 
                The best way to work around this is to catche the Exception and re-send the 
                request as there is nothing else you can do on your part. 
             */
            return null;
        }
    }
    
于 2013-06-06T13:46:49.550 回答