How can I uplo开发者_如何学Goad a file to a google calender event as an attachment? With google labs you can enable file uploading in google calender, but how can I upload a file to a calender event in java?
http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html
I noticed that they have an API which works for creating/editing calender events, but I didn't see anything in regards to file uploads. Thanks.
From the API developer's guide, you can set the content of your CalendarEventEntry through the setContent method:
The entry content is represented by a Content object, a class that can hold either plain text or other forms of content, including XML and binary data. (But the setContent method can also accept a
TextConstruct
).
Then, using the same example listed at the guide, and using the com.google.gdata.data.OtherContent
class of the provided API:
byte[] binaryContent=//... your binary content to attach
OtherContent yourContent=new OtherContent();
yourContent.setBytes(binaryContent);
//don't know if this is mandatory... yourContent.setMimeType(ContentType.ANY);
CalendarEventEntry myEntry = new CalendarEventEntry();
myEntry.setTitle(new PlainTextConstruct("Read the attachment"));
myEntry.setContent(yourContent);
//etc...
DateTime startTime = DateTime.parseDateTime("2006-04-17T15:00:00-08:00");
DateTime endTime = DateTime.parseDateTime("2006-04-17T17:00:00-08:00");
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);
精彩评论