如何将数据库与Google Calender同步

时间:2018-08-29 10:15:44

标签: c# .net google-calendar-api

我正在使用此代码,它可以正常工作,并允许我的应用从使用的Google帐户获取Calendar列表。

UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(

new ClientSecrets
{
    ClientId = "xxx",
    ClientSecret = "xxxx-xxxx",
},
            new[] { CalendarService.Scope.Calendar },
            "support@xxx.com",
            CancellationToken.None).Result;



    // Create the service.
    var service = new CalendarService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName = "xxx",
    });

    CalendarListResource.ListRequest cal = service.CalendarList.List();
    cal.MaxResults = 10;

    var calresult = cal.Execute().Items;

我的问题是,当我执行此操作时,我将所有日历和事件均导入到本地数据库中,因此一个小时后,我需要运行脚本以使用最新的日历和事件信息来更新数据库,因为它们可能添加了新的事件或删除了与Calender相同的内容。

不确定在哪里可以找到建议吗?

1 个答案:

答案 0 :(得分:0)

对于其他人:

答案在这里:

How to access users calendar list and events from google api using access token and refresh token

基本上,您保存令牌,以后再将其用于该日历。