我一直在尝试通过在我的开发控制台中为应用创建的Google服务帐户插入Google日历活动,但我不断在Execute方法上收到无助的404响应。在dev控制台的概述中,我可以看到应用程序正在获取请求,因为calendar.events.insert方法中存在错误实例。没有关于失败的信息。我需要此过程来使用服务帐户进程而不是OAuth2,以便每次需要创建日历事件时都不需要身份验证。
我已经设置了服务帐户,在应用程序名称的情况下,在项目中引用了p12文件。我也进入个人日历并与服务帐户电子邮件地址共享。此外,除了此故障单的范围之外,我还通过管理帐户创建了一个辅助应用程序,并且仅授予对服务帐户的域范围访问权限,以便接收与此相同的无助404错误。
Error Message: Google.Apis.Requests.RequestError
Not Found [404]
Errors [Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
非常感谢任何帮助识别断开连接或错误。
var URL = @"https://www.googleapis.com/calendar/v3/calendars/testcalendarID.com/events";
string serviceAccountEmail = "createdserviceaccountemailaq@developer.gserviceaccount.com";
var path = Path.Combine(HttpRuntime.AppDomainAppPath, "Files/myFile.p12");
var certificate = new X509Certificate2(path, "notasecret",
X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { Google.Apis.Calendar.v3.CalendarService.Scope.Calendar },
}.FromCertificate(certificate));
BaseClientService.Initializer initializer = new
BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Test App"
};
Google.Apis.Calendar.v3.CalendarService calservice = new Google.Apis.Calendar.v3.CalendarService(initializer);
string timezone = System.TimeZone.CurrentTimeZone.StandardName;
var calendarEvent = new Event()
{
Reminders = new Event.RemindersData()
{
UseDefault = true
},
Summary = title,
Description = description,
Location = location,
Start = new EventDateTime()
{
//DateTimeRaw = "2014-12-24T10:00:00.000-07:00",
DateTime = startDateTime,
TimeZone = "America/Phoenix"
},
End = new EventDateTime()
{
//DateTimeRaw = "2014-12-24T11:00:00.000-08:00",
DateTime = endDateTime,
TimeZone = "America/Phoenix"
},
Attendees = new List<EventAttendee>()
{
new EventAttendee()
{
DisplayName = "Joe Shmo",
Email = "joeshmoemail@email.com",
Organizer = false,
Resource = false
}
}
};
var insertevent = calservice.Events.Insert(calendarEvent, URL);
var requestedInsert = insertevent.Execute();
答案 0 :(得分:1)
我遇到了同样的问题。解决方案是添加一个电子邮件客户端,其日历事件要发送。
cat lines.mvg \
| while read a b c d e; do \
if [ x${b/,0/} == x${c/,300} ]; then \
echo "$a $b $c $d $e" ; \
fi; \
done
line 76.5,0 76.5,300 # 193
line 324.5,0 324.5,300 # 193
答案 1 :(得分:0)
所以我发现为了实现这一点,您需要确保访问google.Admin帐户以引用您创建的应用的服务帐户客户端ID。
另一件有用的事情是确保时区采用以下格式“America / Phoenix”
我现在已成功通过服务帐户创建事件而无需身份验证。