2013-06-06 2 views
0

MVC 4 웹 응용 프로그램에서 작업 중입니다. 시나리오가 다음과 같은 기능을 구현하려고합니다. ex : [email protected]에 대한 입력으로 gmail id가 있습니다. 사용자가 이것을 입력하면 응용 프로그램은 해당 전자 메일 아이디의 모든 달력 이벤트를 가져 와서 표시해야합니다.mvc 4 응용 프로그램에서 Gmail 달력 이벤트 가져 오기

나는 this-

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

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

나는이 새로운 오전를 통과하고 난 많은 검색하지만 모든 솔루션을 가지고하지 않았습니다. 도와주세요! 미리 감사드립니다!

+0

오류 또는 문제가 무엇을 겪고 있습니까? 당신이 한 일과 당신이 직면 한 문제를 나눌 수 있습니까? –

+0

내가 직면하고있는 문제는이 문제를 어떻게 시작해야하는지 이해하지 못한다는 것입니다. – Priyanka

+0

"this"는 MVC 또는 Google Calendar API를 의미합니까? ASP.NET MVC, HttpClient 또는 HttpWebRequest에 익숙합니까? –

답변

0

아래 단계를 확인하시기 바랍니다.

  1. Google 데이터 API SDK를 추가하십시오.
  2. 이 코드를 사용하십시오. 한 프로젝트에서이 코드를 작성했지만 Google 캘린더와 관련없는 일부 코드는 제거했습니다. 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; 
        } 
    } 
    
관련 문제