Google Calendar 脚本用于将域的所有日历与外部数据库同步

发布于 2024-11-03 23:12:21 字数 324 浏览 0 评论 0原文

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

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

我目前在尝试决定如何通过谷歌进行身份验证时遇到了困难。由于单个用户每天可以进行的通话量是有限的,因此我实际上无法让一个管理员用户帐户负责同步每个人。

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

非常感谢。

We have google apps for our domain (education). In our student database system we have all the class information.

We would like to write a sync process that forces all faculty and student calendars to be synced with google calendar. This all seems simple enough...minus all the "what ifs" but that will just take time to figure out.

I'm currently hitting a wall when trying to decide how to authenticate with google. Since there are limits on the amount of talking a single user can do per day I can't really have one admin user account in charge of syncing everyone.

Can someone tell me which authentication direction I should take with this? I don't need users to log in, I just need to write to all of their calendars. I have heard mentions of 2 legged OAuth, but I am confused on exactly what is the right answer and really need some guidance on what to use.

Thanks much.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

找回味觉 2024-11-10 23:12:21

以下是我用于类似项目的一些代码片段。我使用了 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 为 .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

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

Here are some snippets of code that I used for a similar project. I used the google api and .net framework which made it a lot easier than using OAuth. These snippets are in 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

In summary I was just using the Calendar Service class provided by google for the .net framework. The FstrEmail is just the email address associated with the calendar and FstrPassword is the regular google password. FURLNoCookie is actually where you specify what calendar it goes to. This is just the XML private sharing URL for the calendar (gotten from calendar settings>private address). When you first get this URL from the calendar it will look something like this

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

Modify it to look like this

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

A similar process can be used for updating and deleting entries. I use this to sync a spreadsheet with multiple google calendars and it works fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文