Java examples for Social Media:Twitter
Follow and unfollow friends
import twitter4j.*; import twitter4j.auth.AccessToken; public class ManageFriends { public static void main(String[] args) { Twitter twitter = new TwitterFactory().getInstance(); String consumerKey = "a"; String consumerSecret = "a"; String accessToken = "a"; String accessTokenSecret = "a"; twitter.setOAuthConsumer(consumerKey, consumerSecret); twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));//www. j a v a2 s . c om try { if (args.length == 2) { String command = args[0]; String screenName = args[1]; if ("follow".equals(command)) { twitter.createFriendship(screenName); System.out.println("@" + screenName); } else if ("unfollow".equals(command)) { twitter.destroyFriendship(screenName); System.out.println("@" + screenName); } } System.out.println("@" + twitter.getScreenName()); PagableResponseList<User> users = twitter .getFriendsStatuses(-1); for (User user : users) { System.out.println("@" + user.getScreenName()); } } catch (TwitterException te) { System.out.println(te.getMessage()); } } }