Manage Twitter Notification - Java Social Media

Java examples for Social Media:Twitter

Description

Manage Twitter Notification

Demo Code

import twitter4j.PagableResponseList;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.auth.AccessToken;

public class ManageNotification {
    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));//from   w w w  .j a  v a  2 s .  c om
        try {
            if (args.length == 2) {
                String command = args[0];
                String screenName = args[1];
                if ("follow".equals(command)) {
                    twitter.enableNotification(screenName);
                    System.out.println("@" + screenName
                            );
                } else if ("leave".equals(command)) {
                    twitter.disableNotification(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());
        }
    }
}

Related Tutorials