Walllzzz
Walllzzz

Reputation: 560

How can I follow a twitter user using Twitter4j framework?

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.

Upvotes: 11

Views: 4680

Answers (3)

Imran Ahmad
Imran Ahmad

Reputation: 216

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"); 

Upvotes: 0

user665270
user665270

Reputation:

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

mTwitter.createFriendship("dj")

Upvotes: 17

Walllzzz
Walllzzz

Reputation: 560

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

Upvotes: 7

Related Questions