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.
No need for id. It will work with username as well.
mTwitter.createFriendship("dj")
Problem solved ,you can follow a user using twitter.createFriendship("twitter id");
method
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");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.