Twitter4J Viewtool Example

Description

Just a quick Example of a Twitter4J viewtool.

Link: https://gist.github.com/cfalzone/5356502

Code

public class TwitterTool implements ViewTool {
    
    private Twitter twitter;
    private boolean inited = false;
    
    public void init(Object initData) { 
        try {
            twitter = new TwitterFactory().getInstance(); 
            inited = true;
        } catch (Exception e) {
            Logger.error(this, "Error getting twitter instance", e);
            inited = false;
        }
    }
 
    public List<Status> getTimeline(String user) {
        if(inited) {
            try {
                return List<Status> statuses = twitter.getUserTimeline(user);
            } catch (Exception e) {
                Logger.error(this, "Error Fetching timeline", e);
                return null;
            }
        } else {
            Logger.info(this, "ViewTool not inited");
            return null;
        }
    }
}