Thursday, August 4, 2011

Tweeting from Java – Failure attempt

            It’s my very first try on this. I think almost I spend around one and half hours on this. But I’m not success. When I am writing this story, my mind says “Don’t waste your time in posting this useless story”. But I want to blog my failures.  It might interest me in my future.

           
             It’s about tweeting from standalone java program. I don’t know why all of a sudden I got this idea. Yes it’s possible through twitter api. Twitter Developers listing libraries for all most all the languages. But as you know that I’m familiar only with Java, below are the twitter api’s suggested by Twitter Developer for Java
  • Scribe by Pablo Fernandez
  • Twitter4J by Yusuke Yamamoto
  • Twitter API ME by ernandesmjr
            I chose Twitter4J. I downloaded the library files.  And tried the below program. It will print you the base URL that is nothing but http:/twitter.com and print you the list of your friend’s timeline.

import twitter4j.Twitter;

public class TwitterMain {   
    public static void main(String[] args) throws Exception {    
      Twitter twitter = new Twitter("username", "password");
      System.out.println(twitter.getBaseURL());  
      System.out.println(twitter.getFriendsTimeline());
    }
}

When I execute this main method I get this below trace,

http://twitter.com/
Exception in thread "main" twitter4j.TwitterException: Connection refused: connect
      at twitter4j.http.HttpClient.httpRequest(HttpClient.java:492)
      at twitter4j.http.HttpClient.get(HttpClient.java:420)
      at twitter4j.Twitter.get(Twitter.java:280)
      at twitter4j.Twitter.get(Twitter.java:232)
      at twitter4j.Twitter.getFriendsTimeline(Twitter.java:549)
      at TwitterMain.main(TwitterMain.java:8)

            I tried all the ways to address this. But it’s a showstopper. Actually the request is getting timed out here. Initially I thought Twitter intensely refusing my request. Twitter services might validate the client ip address.

            Also Twitter api connects the base URL through Http Client only. So tried the standalone Http Client and attempted a simple Google search. Again I get the same response. Looks like my client failed to establish the communication link.

            Since I’m trying this from my office network, it might be a problem with the proxy settings also (My poor guess). Before attempting from my home network I’m blogging my experience. Who knows I might success by tonight itself. I might skip to post my successive Tweet from Java also. 

1 comments:

Kumar said...

My flag already listing there

Post a Comment

Related Posts Plugin for WordPress, Blogger...