Friday, March 28, 2008

Google's GData Java API

This has been out for a while, but I recently realized that Google's GData API provides a way to interact with all Google services (Doc, Calendar, YouTube, Blogger, Picasso, etc) through your own server side code. One nice application for Science Gateways is to write a Web Service that submits grid jobs, writes service state changes to Google Calendar, spits out result synopsis to a blog, and posts visualizations to Picasso or YouTube.

Below is some code liberally borrowed from Blogger, YouTube, and Calendar API gdata examples to show how simple this is. Some notes:


--------------------
Code example below
--------------------
import com.google.gdata.client.*;
import com.google.gdata.client.youtube.*;
import com.google.gdata.data.*;
import com.google.gdata.data.geo.impl.*;
import com.google.gdata.data.media.*;
import com.google.gdata.data.media.mediarss.*;
import com.google.gdata.data.youtube.*;
import com.google.gdata.data.extensions.*;
import com.google.gdata.util.*;

import com.google.gdata.client.*;
import com.google.gdata.data.*;
import com.google.gdata.util.*;
import java.io.IOException;
import java.net.URL;
import java.util.*;

//Google Calendar stuff
import com.google.gdata.client.calendar.*;
import com.google.gdata.data.acl.*;
import com.google.gdata.data.calendar.*;
import com.google.gdata.data.extensions.*;

public class TestBlogger {
String clientID="XXXXX";
String developer_key="XXXXXXX";

String feedUrl="http://gdata.youtube.com/feeds/api/videos/";
String scarFace5sec="http://gdata.youtube.com/feeds/api/videos/egwB7hVIIEc";

GoogleService googleService;
YouTubeService youTubeService;
CalendarService calendarService;

public GoogleService getGoogleService() {
return googleService;
}
public void setGoogleService(GoogleService googleService) {
this.googleService=googleService;
}

public YouTubeService getYouTubeService() {
return youTubeService;
}

public void setYouTubeService(YouTubeService youTubeService) {
this.youTubeService=youTubeService;
}

public void setCalendarService(CalendarService calendarService) {
this.calendarService=calendarService;
}

public CalendarService getCalendarService() {
return this.calendarService;
}

public TestBlogger() throws Exception {
//Replace these with real values.
String userName="me@gmail.com";
String password= "qwerty";

//Log into blogger.
GoogleService myService=new GoogleService("blogger","");
myService.setUserCredentials(userName,password);
setGoogleService(myService);

//Log into YouTube
YouTubeService service = new YouTubeService(clientID, developer_key);
service.setUserCredentials(userName,password);
setYouTubeService(service);

//Log into Calendar
CalendarService calService=new CalendarService(clientID);
calService.setUserCredentials(userName,password);
setCalendarService(calService);
}

public void writeToCalendar(String titleOfEvent,
String contentToPost) throws Exception {
URL postUrl =
new URL("http://www.google.com/calendar/feeds/"+userName+"/private/full");
CalendarEventEntry myEntry = new CalendarEventEntry();

myEntry.setTitle(new PlainTextConstruct(titleOfEvent));
myEntry.setContent(new PlainTextConstruct(contentToPost));

// DateTime startTime = DateTime.parseDateTime("2008-03-18T15:00:00-08:00");
System.out.println((new Date()).toString());
DateTime startTime = new DateTime(new Date());
// DateTime endTime = DateTime.parseDateTime("2008-03-18T17:00:00-08:00");
When eventTimes = new When();
eventTimes.setStartTime(startTime);
// eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);

// Send the request and receive the response:
CalendarEventEntry insertedEntry = calendarService.insert(postUrl, myEntry);

CalendarEventEntry myEntry2 = new CalendarEventEntry();
String now=(new Date()).toString();
myEntry2.setContent(new PlainTextConstruct("Test post at "+now));
myEntry2.setQuickAdd(true);

// Send the request and receive the response:
CalendarEventEntry insertedEntry2 =calendarService.insert(postUrl, myEntry2);
}

public String getBloggerEntryString() throws Exception {
String returnString="";
URL feedUrl=new URL("http://communitygrids.blogspot.com/atom.xml");
Feed resultFeed = googleService.getFeed(feedUrl, Feed.class);

// Print the results
System.out.println(resultFeed.getTitle().getPlainText());
for (int i = 0; i < resultFeed.getEntries().size(); i++) { Entry entry = resultFeed.getEntries().get(i); returnString+=entry.getTitle().getPlainText()+"
";
}
return returnString;
}

public String getVideoFeedString() throws Exception {

String returnString;

VideoFeed videoFeed=youTubeService.getFeed(new URL(feedUrl),
VideoFeed.class);

VideoEntry videoEntry = youTubeService.getEntry(new URL(scarFace5sec),
VideoEntry.class);

returnString="Title: " + videoEntry.getTitle().getPlainText()+"
";
returnString+=videoEntry.getMediaGroup().getDescription().getPlainTextContent()+"
";
return returnString;
}

public Entry createPost(GoogleService myService, String blogID, String title,
String content, String authorName, String userName)
throws ServiceException, IOException {
// Create the entry to insert
Entry myEntry = new Entry();
myEntry.setTitle(new PlainTextConstruct(title));
myEntry.setContent(new PlainTextConstruct(content));
Person author = new Person(authorName, null, userName);
myEntry.getAuthors().add(author);

// Ask the service to insert the new entry
URL postUrl = new URL("http://www.blogger.com/feeds/" + blogID + "/posts/default");
return myService.insert(postUrl, myEntry);
}


public static void main(String[] args) throws Exception {
String blogId=1292929011;
String someName="test";

TestBlogger blog=new TestBlogger();
// System.out.println(blog.getBloggerEntryString());
// System.out.println(blog.getVideoFeedString());
String content="Some post test with the blogger Java api"+"
";
content=blog.getBloggerEntryString()+blog.getVideoFeedString();
blog.createPost(blog.getGoogleService(),
blogId,
"Testing Blogger API",
content,
"Marlon Pierce",
someName);
blog.writeToCalendar("Test Calendar Post",content);
}
}

Thursday, March 27, 2008

Broken TeraGrid RSS News Feeds

[Nagger's Update: the titles were fixed after I posted this. Hopefully reordering will be soon to follow.]

If you have a TeraGrid account, you probably have noticed the 6.02(10)^23 emails you get every day (Ranger is up! Ranger is down...). You can disable all of these by going to 'http://news.teragrid.org/subscribe-db.php. Even better, you can subscribe instead to RSS feeds and get these updates in a sensible fashion.

There are only two problems: the title fields in the feeds are broken and most of the feeds are in newest-entry-last order. The iGoogle RSS reader (for one) assumes that the first entry is the newest (not the oldest) entry.

Here is an example (to pick on the home team): http://news.teragrid.org/feeds/rss-indiana.rss I did notice that TACC had at least fixed their ordering, but most of the other centers have the same problem.

I reported these errors to the help desk like a good soldier, got my trouble ticket, and then...nothing. After a couple of weeks through some back channel emails, I found out that my ticket had been received and that they would fix it within the the year. I am not making this up. No one is willing to take five minutes to fix this simple problem. Probably they don't have any time left after all the meetings.

Friday, March 14, 2008

Testing Blogger API

Two Nice Papers by Jim Grey
SSH Empty Passphrases
Password Protected RSS/Atom Feeds
Get Off My Cloud
Counting Unique IPs in Apache Log Files
XFN Test
BBQ Flickr Mashup
Emacs for C#/.NET/Mono
Running GOAP on PolarGrid Testbed
Polar Grid Matlab Note
More with Shindig and Open Social
Quick Start with Open Social, Shindig
A Little More JavaScript and FaceBook Hacking
Quick Facebook JavaScript and PHP API Notes
Portals and Web Applications
Polar Grid URL
Some Project Zero Thoughts
More Mac OS X Emacs
Birdbath and Globus RSL
Installing and Configuring Globus Services on Mac OS X
Condor-G, Birdbath and TransferOutputRemaps
File Retrieval with BirdBath and Condor-G
Condor-G Plus TeraGrid Example
Returning Standard Output in Condor-G
Globus Client+MyProxy+Pacman on FC7 Notes
Title: Scarface in 5 seconds
...

Wednesday, March 12, 2008

Two Nice Papers by Jim Grey

Thanks to Shrideep for sending these:

G. Bell, J. Gray,  and A. Szalay, "Petascale Computational Systems:Balanced
CyberInfrastructure in a Data-Centric World," IEEE Computer, vol. 39, no 1,
pp. 110-112, Jan. 2006.
http://research.microsoft.com/~gray/papers/Petascale%20computational%20systems.pdf

J. Gray, "Distributed Computing Economics", Computer Systems Theory,
Technology, and Applications, A Tribute to Roger Needham, A. Herbert and K.
Sparck Jones eds., Springer, 2004,pp 93-101
ftp://ftp.research.microsoft.com/pub/tr/TR-2003-24.pdf