Google日历活动未显示在日历中 [英] Google Calendar Event Not Showing in Calendar

查看:185
本文介绍了Google日历活动未显示在日历中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经在Google中创建了一个服务帐户,并使用Calendar API添加事件,此操作之前效果很好,在Google停止并重新激活该帐户后,它无法正常工作

We have created a Service Account in Google and Using Calendar API for adding events, it worked fine before ,after google stopped the account and reactivated it , it didn't work

我们尝试了新的服务帐户,并逐行调试了我们的代码,没有错误,还返回了已创建的事件,但未在日历中显示

We have tried new service account and debugged line by line of our code and no error and also returning created events but not showing in calendar

        CalendarService service = null;
        var serviceAccountCredentialFilePath = 
        Path.Combine(AppDomain.CurrentDomain.BaseDirectory, 
        "ServiceAccount_Key.json");
        if (Path.GetExtension(serviceAccountCredentialFilePath).ToLower() 
        == ".json")
        {
            GoogleCredential credential;

            string[] scopes = new string[] {
                CalendarService.Scope.Calendar, // Manage your calendars
                CalendarService.Scope.CalendarReadonly // View your Calendars
             };
            using (var stream = new FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read))
            {
                credential = GoogleCredential.FromStream(stream)
                     .CreateScoped(scopes);
            }
            // Create the service.
            service = new CalendarService(new BaseClientService.Initializer
            {
                HttpClientInitializer = credential,
                ApplicationName = "Esoco"
            });
        }
        // End //

        // Insert Event //
        var myEvent = new Event
        {
            Id = guid,
            //Transparency =  "OPAQUE",
            Summary = subject,
            Location = location,
            Start = new EventDateTime { TimeZone = timezone, DateTime = start },
            End = new EventDateTime { TimeZone = timezone, DateTime = end },
            Attendees = objattendees,
            Organizer = organizerdata,
            Description = summary,

        };

        myEvent.Start.DateTimeRaw = myEvent.Start.DateTimeRaw.Replace("Z", "");
        myEvent.End.DateTimeRaw = myEvent.End.DateTimeRaw.Replace("Z", "");

        //myEvent.ICalUID

        var recurringEvent = service.Events.Insert(myEvent, "primary");
        recurringEvent.SendNotifications = true;
        try
        {
            var outputofevent = recurringEvent.Execute();
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "Alertscript", "alert('"+outputofevent.Status+"')", true);
        }

在日历中插入了预期结果,但在日历中未显示实际结果

Expected Result is Inserted Event Display in Calendar but Actual Result is Not Displayed in Calendar

推荐答案

在过去的几周中,我的团队遇到了同样的问题,即
,这就是我团队的解决方法。

In the past few weeks, my team have the same issues, and this is what my team's workaround.

我们的情况


  1. 我们创建一个名为 google-calendar@mycompany.iam.gserviceaccount.com

  2. 我们使用1)中的服务帐户凭据来获取Google Calendar API

  3. 在服务帐户的日历中创建一个事件,如下面的代码



calendar.events.insert({
  calendarId: 'primary', // it will create an event into service account's calendar
  resource: data,
  sendNotifications: true
})






我们为解决此问题所做的工作。


What we have done for a workaround.


  1. 创建新公司的用户(假设 system @ mycompany.com

  2. 通过服务帐户将 system@mycompany.com 的日历共享


    • 转到日历>设置>与特定的人共享,然后

    • 添加 google- calendar@mycompany.iam.gserviceaccount.com 与对事件进行更改

  1. Create a new company's user (let's say system@mycompany.com)
  2. Share system@mycompany.com's calendar with a service account by
    • going to "Calendar > Settings > Share with specific people" then
    • adding google-calendar@mycompany.iam.gserviceaccount.com with "Make changes to events"



calendar.events.insert({
  calendarId: 'system@mycompany.com', // << we changed from 'primary' to just-created-user
  resource: data,
  sendNotifications: true
})

更改后,创建的事件将按其应有的方式显示在Google日历中。

After changing it, the created-event will be shown in Google Calendar as what it should.

希望这会有所帮助

这篇关于Google日历活动未显示在日历中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆