2013-06-06 2 views
0

Я работаю над веб-приложением mvc 4. Я хочу реализовать функциональность, в которой сценарий выглядит следующим образом: В качестве ввода для ex: [email protected] будет идентификатор gmail. Когда пользователь вводит это, приложение должно получить все события календаря соответствующего идентификатора электронной почты и отобразить их.fetch события в календаре gmail в mvc 4 application

Я прошел через 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

«это» означает API MVC или Google Calendar? Вы знакомы с ASP.NET MVC, HttpClient или HttpWebRequest? –

ответ

0

Пожалуйста, проверьте следующие шаги.

  1. Добавить API данных Google Data API.
  2. Попробуйте этот код .. Я написал этот код для одного проекта, но удалил некоторые коды, не связанные с Google Calender. Если вы не хотите использовать 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; 
        } 
    }