List<DocumentListEntry> entries = resultFeed.getEntries();
for (DocumentListEntry entry : entries) {
MediaContent content = (MediaContent)entry.getContent();
System.out.println("View '" + entry.getTitle().getPlainText() + "' at " + content.getUri());
}
Showing posts with label java. Show all posts
Showing posts with label java. Show all posts
Retrieving a document's content URL in Java
Posted by
Eric (Google)
on
Monday, January 05, 2009
If you have a published document, its contents can be viewed by fetching the DocumentListEntry object's <content> src URL:
Catching Exceptions from the Java Client Library
Posted by
Trevor Johns
on
Sunday, September 21, 2008
Just like our other client libraries, if you're using the Java client library and encounter a server error, an exception will be generated. This will cause Java to stop in its tracks and print out the contents of the exception. While this is useful for debugging, in a production application you'll probably want your application to fail gracefully, perhaps displaying a nice error message to your users.
You can do this by wrapping your code in a try block and using an catch statement:
try {
// Do something that accesses the network
} catch (IOError e) {
// Insert custom error handling code here.
System.out.println(e.toString());
} catch (ServiceException e) {
// Insert custom error handling code here.
System.out.println(e.toString());
}
Most errors will be instances of either IOError or ServiceException, depending on the cause.
Retrieving a single document entry using the Java client library
Posted by
Jochen Hartmann (Google)
on
Wednesday, September 03, 2008
The snippet below demonstrates how to retrieve a single DocumentListEntry using the Java client library:
import java.net.URL;
import com.google.gdata.client.docs.DocsService;
import com.google.gdata.data.docs.DocumentListEntry;
public class DocumentListGetEntry {
public static void main(String[] args) {
try {
DocsService docsService = new DocsService("Document List Demo");
docsService.setUserCredentials("[email protected]", "secret");
URL documentURI = new URL("http://docs.google.com/feeds/documents/private/full/spreadsheet%3Apc6ppXdYxYkSSOvE8tCUELw");
DocumentListEntry entry = docsService.getEntry(documentURI, DocumentListEntry.class);
System.out.println(entry.getTitle().getPlainText());
} catch (Exception e) {
System.err.println(e.toString());
}
}
}
Create Calendar Gadget using the Google Data Java client library.
Posted by
Austin Chau (Google)
on
Monday, August 04, 2008
Create Calendar Gadget (WebContent event) using the Google Data Java client library.
public DateTime getToday() {
Date today = new Date();
DateTime datetime = new DateTime(today);
datetime.setDateOnly(true);
return datetime;
}
public DateTime getTomorrow() {
long oneDay = 24 * 60 * 60 * 1000;
Date today = new Date();
DateTime datetime = new DateTime(new Date(today.getTime() + oneDay));
datetime.setDateOnly(true);
return datetime;
}
public void createWebContent() throws Exception {
URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/private/full");
CalendarEventEntry entry = new CalendarEventEntry();
entry.setTitle(new PlainTextConstruct("create web content"));
entry.setContent(new PlainTextConstruct("This event is created by Java client library"));
DateTime startTime = getToday();
DateTime endTime = getTomorrow();
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
entry.addTime(eventTimes);
WebContent wc = new WebContent();
wc.setTitle("title");
wc.setType("text/html");
wc.setIcon("http://www.google.com/intl/en_ALL/images/logo.gif");
wc.setUrl("http://www.google.com");
wc.setWidth("800");
wc.setHeight("600");
entry.setWebContent(wc);
// Send the request and receive the response:
calendarService.insert(feedUrl, entry);
System.out.println("Calendar Gadget is created");
}
Subscribe to:
Comments (Atom)