Java Reference
In-Depth Information
"RT @wwwtxt: Hi, is there anyone out there on the net this Easter?
I will be back again tomorrow if you miss me today. ?92APR"
"RT @BobVila: Here's something everyone can make! 5 Things to do with...
Junk Mail! http://t.co/2qyTBJEkQX http://t.co/32ymeLUff9"
"RT @hari: How @reddit @Disqus @smittenkitchen are taming the 'Wild West'
of online comments | http://t.co/I8f2FKJ694"
"RT @MDogGeist: so the wii-u is as old as the dreamcast when it was killed
and the wii-u has sold less than half what the dreamcast did..."
"I've now been on twitter for half an hour or so, but I'm \"totally coding
right now\" in my head. Procrastinators, unite!"
If you want, you can take some time to familiarize yourself with the GSON library, but its usage is
relatively straightforward and can be derived quickly by using Eclipse's context pop‐ups. You can
also explore the Twitter REST service somewhat further to get out and post different information.
Note One interesting way to use the Twitter REST service is through the
search/tweets.json GET endpoint (this requires a single mandatory param-
eter, q , which contains the search query). You can use this, for example, to
search for tweets users are posting about you or your company.
This concludes the section on accessing REST services. This section has covered a lot of ground, so
feel free to go over the code again or experiment some more to get a feel for how everything works.
Since REST has become so popular in recent years, you might want to explore the developer's sec-
tion of your favorite productivity site or social network to see if they're offering something similar.
Note These examples have been using a set of libraries and built‐in classes
to deal with HTTP communication and OAuth for you. However, many RESTful
services also offer even higher‐lever libraries (or third parties offer them),
providing “bindings” to a number of languages, Java often among them. For
Twitter, for instance, you can check out the Twitter4J library at http://t wit-
ter4j. org/ , which offers a Java library to interact with Twitter's REST service.
Methods and classes offered by such libraries are oftentimes more closely
defined to the actual service (i.e., a method called postTweet ), but since the
goal here is to familiarize yourself with REST services in general, a more “pure”
approach is applied.
You've now seen how to work with Java's built‐in HttpURLConnection class to access RESTful ser-
vices, as well as used Google's OAuth and HTTP client libraries to access more complex services.
You've also seen how to parse XML and JSON.
As a final exercise, the next Try It Out shows how to access another REST service—Facebook.
Search WWH ::




Custom Search