views:

2529

answers:

7

The twitter API site lists 3 java twitter libaries.

Do you know others? What are your experiences in support, ease of use, stability, community, etc.

+7  A: 

I think Twitter4j is good one it is most upto date API

Rahul Garg
+11  A: 

I just took a look at them.

JTwitter definitely looks like the weakest of the three. It doesn't appear to have been updated lately, doesn't cover much of the Twitter API, and doesn't appear to have any releases besides the initial one. On the upside, it's LPGL licensed, comes packaged with what little extra code it needs, and looks small and simple to understand.

The other two, java-twitter and Twtter4J look much closer in quality. Both cover the core API, and both have all the accouterments of normal open-source projects: publicly available source code repository, on-line docs, active mailing lists, and recent development activity.

However, Twitter4J looks to be the leader. From the docs, its API coverage appears to be more complete. The mailing list is definitely more active. The docs are much better. And most importantly to me, the releases have been more frequent. java-twitter has one release up, the "0.9-SNAPSHOT" release about 4 months ago. Twitter4J has had several releases in that time period, including 2.0.0 and incremental releases up through 2.0.8, fixing issues and adding support for new Twitter APIs.

I'm going to start with Twitter4J; if you don't hear back, assume it was just great for me.

William Pietri
After a month of poking, Twitter4J seems pretty swell. I'm entirely in favor of it.
William Pietri
A: 

I have selected Twitter4j because a lot of people are working on it. And its easy to find out some contents on Internet about it.

Tahir Akram
+4  A: 

I use Twitter4J and have yet to have a problem with it. I actually like it a lot.

The OAuth example they give on their website is the biggest nuisance -- it's not helpful. Here's my OAuthServlet code if you're interested (or anyone else). I know this question is rather old, so I'm putting it in here more for search results.

package com.appspot.yourmomstwat;

import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import twitter4j.*;
import twitter4j.http.*;


@SuppressWarnings("serial")
public class OAuthServlet extends HttpServlet {

    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {

        HttpSession sess = req.getSession(true);
        RequestToken requestToken = (RequestToken) sess.getAttribute("requestToken");



     if (sess.getAttribute("twitter_user_id") != null) {
      resp.setContentType("text/plain");
      PrintWriter out = resp.getWriter();
      if (req.getRequestURI().indexOf("logout") > 3) {
          sess.removeAttribute("twitter_user_id");
          out.println("You're now logged out.");
         } else {
          out.println("You're already logged in!");
         }
        } else if (req.getRequestURI().indexOf("callback") > 3 && req.getParameter("oauth_token").length() > 0 && requestToken != null) {

         handleCallback(req, resp, sess);
         if (sess.getAttribute("oauth_previous") != null) {
          resp.sendRedirect((String) sess.getAttribute("oauth_previous"));
          sess.removeAttribute("oauth_previous");
         }

     } else {

      sendToTwitter(resp, sess);
      sess.setAttribute("oauth_previous", req.getHeader("Referer"));
     }

    }

    private void sendToTwitter(HttpServletResponse resp, HttpSession sess) throws IOException {

        RequestToken requestToken = (RequestToken) sess.getAttribute("requestToken");

        try {
         Twitter twitter = new TwitterCnx().registerOAuth().get();

      requestToken = twitter.getOAuthRequestToken();
      sess.setAttribute("requestToken", requestToken);

         resp.sendRedirect(requestToken.getAuthorizationURL());


     } catch (TwitterException e) {
      PrintWriter out = resp.getWriter();
      out.println(e.getStackTrace());
     }
    }

    private void handleCallback(HttpServletRequest req, HttpServletResponse resp, HttpSession sess) throws IOException {

     RequestToken requestToken = (RequestToken) sess.getAttribute("requestToken");
     sess.removeAttribute("requestToken");
     String secret = req.getParameter("oauth_token");

     resp.setContentType("text/plain");
     PrintWriter out = resp.getWriter();

        try {
      Twitter t = new TwitterCnx().registerOAuth().get();

      AccessToken accessToken = t.getOAuthAccessToken(requestToken.getToken(), secret);
         long id = (long) t.verifyCredentials().getId();

      storeAccessToken(id, accessToken,sess);
      sess.setAttribute("twitter_user_id", id);

      out.println("You're now logged in!");

     } catch (TwitterException e) {
      out.println("Something went wrong. Sorry about that. Please try again.");
     }

    }



    private void storeAccessToken(Long id, AccessToken at, HttpSession sess) {
     //you probably want to persist this somewhere other than in sessions.
     sess.setAttribute("secret", at.getTokenSecret() );
     sess.setAttribute("token", at.getToken());
     //also, don't forget to persist the user id alongside the token.
    }
}

I use the class TwitterCnx as a wrapper for twitter4j.Twitter. TwitterCnx defines my OAuth consumer stuff and returns a Twitter object. It's a final class with static methods so I don't produce more than one Twitter object per app instance.

Ted Pennings
A: 

Twitter4j is painfully slow. I created a twitter api from scratch at least 10 times faster than twitter4j. I can post benchmarks when I have time. My api is in it's infancy, and has a great architecture. However, it needs help with people to fill in the blanks by creating derived classes for all the various requests.

It currently only supports three requests. All you have to do to create a new request is to inherit from baserequest and implement the abtract methods and properties: String getPage(int i); String getUrl(); void parseResponse(String response); Also you will need to generate the pojo (plain old java object) shells for the object model.

Anyone interested?

Learn more here:

Anyone Want To Collaborate On A Far Faster Java Twitter API Than Any That Currently Exist?

http://j.mp/9l5yz1

devadvocate
+2  A: 

Ahem; JTwitter is actively maintained, regularly updated (version 1.6.2 released today), and covers most of the Twitter API.

It's missing only (1) a method for setting your profile image and a few other profile settings, and (2) methods for the new streaming API. Other than that, it's pretty complete. Status updates, timelines, friendships, lists, searches, etc.

It's also fast and robust. Twitter can be flaky in places and JTwitter has work-arounds and informative exceptions to make your life easier.

As the main JTwitter developer, I am rather biased! But the feedback from developers using JTwitter is also very positive.

Daniel Winterstein
A: 

There's also TweetStream4J which is a Java binding for the Twitter Streaming API. It's pretty simple, and unlike the last time I used it, the author has updated it to include a pom.xml file so you can build it. It's pretty simple and quick when I last used it (from Scala).

Tom Morris