问题描述
我一直在试图通过插入这是在我的开发控制台应用程序创建的谷歌服务帐户谷歌日历事件,但我不断地得到一个无奈的404响应回到Execute方法。在开发者控制台中的概述,我可以看到,由于有上calendar.events.insert方法错误的情况下,应用程序越来越请求。有什么失败的信息。我需要这个过程中使用的服务帐户的过程,而不是这样的OAuth2每个日历事件需要创建时间不要求身份验证。
我已经设置了服务帐户,给定应用程序的名称,在项目中所引用的P12文件。我也,已经进入个人日历,并已与该服务帐户的电子邮件地址分享。此外,超出此票的范围,我创建了一个应用程序辅助,通过管理帐户,并已授予域范围访问服务帐户只接收相同的无奈404错误,这是现在给。
错误信息:Google.Apis.Requests.RequestError
未找到[404]
错误[信息[未找到]地址[ - ]原因[NOTFOUND]域[全球]
任何识别断开或错误帮助将不胜AP preciated。
VAR URL = @https://www.googleapis.com/calendar/v3/calendars/testcalendarID.com/events
字符串serviceAccountEmail =createdserviceaccountemailaq@developer.gserviceaccount.com;
VAR路径= Path.Combine(HttpRuntime.AppDomainAppPath,文件/ myFile.p12);
VAR证书=新X509Certificate2(路径,notasecret
X509KeyStorageFlags.Exportable); ServiceAccountCredential证书=新ServiceAccountCredential(
新ServiceAccountCredential.Initializer(serviceAccountEmail)
{
范围=新[] {} Google.Apis.Calendar.v3.CalendarService.Scope.Calendar,
} .FromCertificate(证书));
BaseClientService.Initializer初始化=新
BaseClientService.Initializer()
{
HttpClientInitializer =凭证,
应用程序名称=测试应用程序
};
Google.Apis.Calendar.v3.CalendarService calservice =新Google.Apis.Calendar.v3.CalendarService(初始化); 字串时区= System.TimeZone.CurrentTimeZone.StandardName;
VAR calendarEvent =新事件()
{
提醒=新Event.RemindersData()
{
UseDefault =真
},
摘要=称号,
说明=描述,
位置=位置,
启动=新EventDateTime()
{
// DateTimeRaw =2014-12-24T10:00:00.000-07:00,
日期时间=的startDateTime,
时区=美国/凤凰
},
结束=新EventDateTime()
{
// DateTimeRaw =2014-12-24T11:00:00.000-08:00,
日期时间= endDateTime,
时区=美国/凤凰
},
与会者=新的List< EventAttendee>()
{
新EventAttendee()
{
显示名称=乔Shmo
电子邮件=joeshmoemail@email.com
主办单位=假,
资源= FALSE
}
}
};
VAR insertevent = calservice.Events.Insert(calendarEvent,URL);
变种requestedInsert = insertevent.Execute();
所以,我发现这个工作,你需要确保你访问google.Admin账户引用应用程序的服务帐户的客户ID您创建的。
另一件事,是帮助确保该时区是按以下格式:美国/凤凰
我现在已经成功地创建通过服务帐户事件而无需验证。
I have been trying to insert a Google calendar event via Google service account that was created for an app in my dev console, but I am continually getting a helpless 404 response back on the Execute method. In the overview of the dev console I can see that the app is getting requests because there are instances of errors on the calendar.events.insert method. There is no information on what is failing. I need this process to use the Service account process instead of OAuth2 so as to not require authentication each time a calendar event needs to be created.
I have set up the service account, given the app a name, have the p12 file referenced in the project. I've also, gone into a personal calendar and have shared with the service account email address. Also, beyond the scope of this ticket, I have created a secondary app, through an administration account and have granted domain wide access to the service account only to receive the same helpless 404 error that this is now giving.
Error Message: Google.Apis.Requests.RequestError
Not Found [404]
Errors [Message[Not Found] Location[ - ] Reason[notFound] Domain[global]
Any help identifying a disconnect or error would be greatly appreciated.
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();
So I found out that for this to work, You need to make sure that you access the google.Admin account for referencing the service account Client ID of the app you created.
Another thing that helps is making sure the timezone is in the following format "America/Phoenix"
I have now successfully created events through the service account WITHOUT authentication.
这篇关于通过服务帐户谷歌API日历V3事件将使用Asp.Net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!