我正在使用Google Calendar API V3和OAuth2 & .NET。 我的身份驗證是由服務帳戶,因爲我需要運行它作爲服務,沒有用戶界面。 我經過了很多努力來驗證憑據,但由於某種原因,我無法在日曆上創建活動(&是的,我與我分享了它...)。使用服務器帳戶和.NET進行的使用Google Calendar API的身份驗證
我發現了很多關於某些相同問題的問題,但都在php中,我不知道或認爲它會幫助我。
我尋求一些幫助。謝謝
String serviceAccountEmail = "[email protected]";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.MachineKeySet |X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { CalendarService.Scope.Calendar }
}.FromCertificate(certificate));
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Calendar API Sample",
});
Event e = new Event()
{
Summary = "Appointment1",
Location = "42.138679, -88.045519",
Start = new EventDateTime()
{
DateTime = DateTime.Now,
TimeZone = "Asia/Jerusalem"
},
End = new EventDateTime()
{
DateTime = DateTime.Now.AddDays(1),
TimeZone = "Asia/Jerusalem"
},
};
Event createdEvent = service.Events.Insert(e, "primary").Execute();
什麼是錯誤? – peleyal
我一直在努力與谷歌.NET庫以及。 API看起來不錯,但它只是一些問題1)每個版本似乎完全打破了最新版本,並且2)沒有好的示例應用程序,只是開發人員需要拼湊在一起的代碼片段。 – Craig
1.圖書館是BETA時發生了很大的變化。但是,現在已經達到了GA,不會有任何不兼容的變化。 2. 我們的示例存儲庫中有少量樣本 - https://code.google.com/p/google-api-dotnet-client/source/browse?repo=samples。請記住,這是一個開源項目,所以如果你將來會共享一個樣本,它將會很棒。 – peleyal