2011-04-27 58 views
1

我們有谷歌應用程序爲我們的域名(教育)。在我們的學生數據庫系統中,我們有所有的班級信息。谷歌日曆腳本同步域的所有日曆與外部數據庫

我們想寫一個同步過程,強制所有的教師和學生的日曆與谷歌日曆同步。這一切似乎很簡單......減去所有「假設」,但這只是需要時間來弄清楚。

當我試圖決定如何使用谷歌進行身份驗證時,我正在打牆。由於單個用戶每天可以進行的通話量有限制,因此我無法真正擁有一個負責同步所有人的管理員用戶帳戶。

有人可以告訴我,我應該採取哪一個認證方向?我不需要用戶登錄,我只需要寫入所有日曆。我聽說過提及2條OAuth,但我很困惑確切的答案是什麼,真的需要一些關於如何使用的指導。

非常感謝。

回答

0

以下是我用於類似項目的一些代碼片段。我使用了google api和.net框架,這比使用OAuth更容易。這些片段在Visual Basic中

Imports Google.GData 
Imports Google.GData.Client 
Imports Google.GData.Calendar 

.....Various Property Fields for the class go here..... 

Public Sub AddEvent() 
    Try 
     Dim theEvent As New EventEntry 
     Dim theCalendarService As CalendarService = New CalendarService(FProgID) 
     Dim theTime As New Extensions.When(FEventStartTime, FEventEndTime) 
     Dim theEntry As AtomEntry 


     If FAllDay = True Then 
      theTime.AllDay = True 
     Else 
      theTime.AllDay = False 
     End If 

     theEvent.Title.Text = FEventTitle 
     theEvent.Times.Add(theTime) 

     If Not FDescription = "" Then 
      theEvent.Content.Content = FDescription 
     End If 
     If Not FEventLocation = "" Then 
      Dim theLocation As New Extensions.Where 
      theLocation.ValueString = FEventLocation 
      theEvent.Locations.Add(theLocation) 
     End If 
     If Not FAuthor = "" Then 
      Dim theAuthor As New AtomPerson 
      theAuthor.Name = FAuthor 
      theEvent.Authors.Add(theAuthor) 
     End If 

     theCalendarService.setUserCredentials(FstrEmail, FstrPassword) 
     theEntry = theCalendarService.Insert(FURLNoCookie, theEvent) 
     FStatus = "Event added successfully to Google Calendar" 
    Catch ex As Exception 
     FStatus = "Failed: Event was added to Job List, but not Google Calendar" 
    End Try 
End Sub 

總之,我只是使用Google提供的Calendar服務類來提供.net框架。 FstrEmail只是與日曆關聯的電子郵件地址,FstrPassword是普通的谷歌密碼。 FURLNoCookie實際上是您指定要傳送的日曆的位置。這只是日曆的XML專用共享URL(從日曆設置>私人地址獲取)。當你第一次從日曆中得到這個URL會是這個樣子

http://www.google.com/calendar/feeds/somebody%40gmail.com/private-188ba1932aa23d4a64ag712db232bfe8b/basic 

修改它看起來像這樣

http://www.google.com/calendar/feeds/somebody%40gmail.com/private/full 

一個類似的過程可用於更新和刪除條目。我用它來同步電子表格與多個谷歌日曆,它工作正常。

+0

是的,我也在考慮這個問題,但是由於一天的要求太多,我想我最終會陷入潛在的障礙。我們正在尋找一個簡單的10-15k不同的活動,以便每天同步。你有沒有遇到麻煩? – wilbbe01 2011-04-27 16:28:09

+0

我沒有遇到任何問題。但是,我的負載在高負載下從未經過負載測試。我所做的最多的是每天約一百人。 – ThinkerIV 2011-04-27 18:10:10