Create and delete twitter block - Java Social Media

Java examples for Social Media:Twitter

Description

Create and delete twitter block

Demo Code

import twitter4j.*;
import twitter4j.auth.AccessToken;

public class ManageBlocks {
    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));// w  ww.jav a 2 s. c  o  m
        try {
            if (args.length == 2) {
                String command = args[0];
                String screenName = args[1];
                if ("block".equals(command)) {
                    twitter.createBlock(screenName);
                    System.out.println("@" + screenName);
                } else if ("unblock".equals(command)) {
                    twitter.destroyBlock(screenName);
                    System.out.println("@" + screenName);
                }
            }
            System.out.println("@" + twitter.getScreenName());
            ResponseList<User> users = twitter.getBlockingUsers(-1);
            for (User user : users) {
                System.out.println("@" + user.getScreenName());
            }
        } catch (TwitterException te) {
            System.out.println(te.getMessage());
        }
    }
}

Related Tutorials