2010-01-27 75 views
5

我正在嘗試將某個事件添加到Google日曆中的特定日曆,而我只是沒有找到如何。這是我的代碼:使用GData API向「特定」Google日曆添加事件

 CalendarService service = new CalendarService("MyTEst"); 
     service.setUserCredentials("Username", "Password"); 
     EventEntry entry = new EventEntry(); 

     // Set the title and content of the entry. 
     entry.Title.Text = "title"; 
     entry.Content.Content = "test"; 

     // Set a location for the event. 
     Where eventLocation = new Where(); 
     eventLocation.ValueString = "Location"; 
     entry.Locations.Add(eventLocation); 

     When eventTime = new When(DateTime.now, DateTime.now.AddDays(2)); 
     entry.Times.Add(eventTime); 

     Uri postUri = new Uri("http://www.google.com/calendar/feeds/default/private/full"); 

     // Send the request and receive the response 
     AtomEntry insertedEntry = service.Insert(postUri, entry); 

任何人都可以幫我解決這個問題嗎?

編輯

也許我應該提到這fonctionnability僅僅是一個網站的管理員,其想要伊斯利添加會合,並注意自己的谷歌日曆,讓我automaticaly與「硬編碼」認證的可訪問值,所以我確信用戶名和密碼都可以。

回答

6

您的代碼使用默認的Google日曆處理您指定的用戶名和密碼。 (IE使用[email protected]的默認日曆)你可以看到這個,因爲URI指向「/ feed/default/private」。如果您想將活動發佈到其他日曆,則用戶名必須有權發佈到該日曆,並且您需要發佈到該日曆私人uri。

編輯: 這個私人URL的默認格式爲「http://www.google.com/calendar/feeds/CALENDAR_ID/private/full

要查找日曆ID,它是在谷歌日曆的日曆設置頁面旁邊的日曆地址。它會與此類似:

「***************************@group.calendar.google.com」

最後的網址是:

編輯: 「http://www.google.com/calendar/feeds/ ***************************@group.calendar.google .COM /私營/全」

這會在你的Uri postUri = new Uri();

編輯:

我的錯誤是我提到你還需要在private之後加上私鑰。你實際上並不需要這樣做。我已驗證可以通過刪除私鑰成功發佈到輔助日曆。

+0

非常感謝DanJo519。我現在就試試這個! – 2010-01-27 21:22:05

+0

我試過了,它仍然失敗成爲一個錯誤;執行請求失敗:google.com/calendar/feeds/[email protected]/private-PRIVATE_KEY/full。我不明白。我已經在最後嘗試了「全部」或「基本」(基本是從谷歌默認提供的,但我已經嘗試過,因爲太完美了,所以你說了這樣的話)。無論如何,沒有人工作:( – 2010-01-27 22:01:03

+1

我已經做了修改我的答案是,你實際上不需要包含-PRIVATE_KEY,如果刪除了,你可以發佈,假設你在日曆上有寫權限,我已經用我的一個輔助日曆成功測試過了。 – 2010-01-29 15:39:01

相關問題