我们已经在Google中创建了一个服务帐户,并使用Calendar API添加事件,但在Google停止该帐户并重新激活该帐户之后,它无法正常工作
我们尝试了新的服务帐户,并逐行调试了我们的代码,没有错误,还返回了已创建的事件,但未显示在日历中
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);
}
在日历中插入了预期结果,但在日历中未显示实际结果
答案 0 :(得分:2)
请记住,以下代码将您的事件插入服务帐户的主日历
var recurringEvent = service.Events.Insert(myEvent, "primary");
要查看这些事件,您需要执行一个events.list或邀请其他人参加该事件,以便他们可以在自己的日历中看到它。
此外,论坛上目前还存在关于未发送邀请https://issuetracker.google.com/issues/140746812的问题
答案 1 :(得分:1)
在过去的几周中,我的团队遇到了同样的问题, 这就是我团队的解决方法。
我们的情况
google-calendar@mycompany.iam.gserviceaccount.com
的服务帐户calendar.events.insert({
calendarId: 'primary', // it will create an event into service account's calendar
resource: data,
sendNotifications: true
})
我们为解决此问题所做的事情。
system@mycompany.com
)system@mycompany.com
的日历
google-calendar@mycompany.iam.gserviceaccount.com
中添加“对事件进行更改” calendar.events.insert({
calendarId: 'system@mycompany.com', // << we changed from 'primary' to just-created-user
resource: data,
sendNotifications: true
})
更改后,创建的事件将按原样显示在Google日历中。
希望这会有所帮助