2010-01-27 74 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

相关问题