11

I need my Java Twitter application to be able to follow a user in twitter. When I pass it the user ID as a string, the application follow it automatically. I couldn't find the method that can do that in Twitter4j.

Stephan
  • 41,764
  • 65
  • 238
  • 329
Walllzzz
  • 550
  • 1
  • 5
  • 16

3 Answers3

17

No need for id. It will work with username as well.

mTwitter.createFriendship("dj")
Stephan
  • 41,764
  • 65
  • 238
  • 329
7

Problem solved ,you can follow a user using twitter.createFriendship("twitter id"); method

Nishant
  • 54,584
  • 13
  • 112
  • 127
Walllzzz
  • 550
  • 1
  • 5
  • 16
0

The following configuration will do it:

ConfigurationBuilder cb =new ConfigurationBuilder();
        cb.setDebugEnabled(true)
          .setOAuthConsumerKey("******")
          .setOAuthConsumerSecret("******")
          .setOAuthAccessToken("*******")
          .setOAuthAccessTokenSecret("********");

        //In case of proxy 
        //cb.setHttpProxyHost("******").setHttpProxyPort(8080);


        TwitterFactory twitterFactory=new TwitterFactory(cb.build());
        Twitter twitter=twitterFactory.getInstance();

         twitter.createFriendship("twitter id"); 
Imran Ahmad
  • 206
  • 1
  • 13