【问题标题】:Google Calendar Script to sync all calendars of a domain with external database用于将域的所有日历与外部数据库同步的 Google 日历脚本
【发布时间】:2011-08-13 23:16:14
【问题描述】:

我们的域(教育)有谷歌应用程序。在我们的学生数据库系统中,我们拥有所有班级信息。

我们想编写一个同步过程,强制所有教师和学生日历与谷歌日历同步。这一切似乎都很简单......减去所有“假设”,但这需要时间来弄清楚。

我目前在尝试决定如何通过 google 进行身份验证时遇到了困难。由于单个用户每天可以进行的通话量受到限制,因此我真的不能拥有一个管理员用户帐户来负责同步所有人。

有人能告诉我我应该采用哪个身份验证方向吗?我不需要用户登录,我只需要写入他们所有的日历。我听说过 2 腿 OAuth,但我对究竟什么是正确答案感到困惑,并且确实需要一些关于使用什么的指导。

非常感谢。

【问题讨论】:

    标签: oauth google-api google-calendar-api google-authentication


    【解决方案1】:

    这是我用于类似项目的一些 sn-ps 代码。我使用了 google api 和 .net 框架,这比使用 OAuth 更容易。这些 sn-ps 在 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
    

    总之,我只是使用谷歌为 .net 框架提供的日历服务类。 FstrEmail 只是与日历关联的电子邮件地址,而 FstrPassword 是常规的 google 密码。 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
    

    类似的过程可用于更新和删除条目。我用它来将电子表格与多个谷歌日历同步,它工作正常。

    【讨论】:

    • 是的,我也在考虑这个问题,但我认为由于一天内的请求太多,我最终会遇到潜在的阻塞。我们正在研究每天要同步的简单 10-15k 不同的事件。你遇到过这个问题吗?
    • 我没有遇到任何问题。然而,我的从未在如此高的负载下进行负载测试。我每天做的最多的是一百个左右。
    猜你喜欢
    • 1970-01-01
    • 2016-08-30
    • 1970-01-01
    • 2019-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多