Example usage for twitter4j Twitter destroyFriendship

List of usage examples for twitter4j Twitter destroyFriendship

Introduction

In this page you can find the example usage for twitter4j Twitter destroyFriendship.

Prototype

User destroyFriendship(long userId) throws TwitterException;

Source Link

Document

Allows the authenticating users to unfollow the user specified in the ID parameter.
Returns the unfollowed user in the requested format when successful.

Usage

From source file:DestroyFriendship.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.DestroyFriendship [screen name]
 *
 * @param args message//w  w w.j a v a 2  s .c  o  m
 */
public void destroyFriendship() {

    ShowFriendshi df = new ShowFriendshi();

    ArrayList<Long> getFilteredtarget = df.showFriendship();

    try {
        Twitter twitter = new TwitterFactory().getInstance();
        User user;
        String get;
        DefaultListModel m1 = new DefaultListModel();
        for (Long target : getFilteredtarget) {

            user = twitter.showUser(target);
            get = user.getScreenName();

            if (!get.equalsIgnoreCase("prometheanBrain") && !get.equalsIgnoreCase("tweetrackdevs")) {
                m1.addElement(get);
                twitter.destroyFriendship(target);
            }

            System.out.println("Successfully unfollowed [" + target + "].");
        }
        MainActivity.deletedList.setModel(m1);

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to unfollow: " + te.getMessage());

    }
}

From source file:com.github.moko256.twitlatte.ShowUserActivity.java

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ThrowableFunc throwableFunc = null;//from w w w . j a v  a2 s .co m
    @StringRes
    int didAction = -1;
    Twitter twitter = GlobalApplication.twitter;

    switch (item.getItemId()) {
    case R.id.action_share:
        startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND).setType("text/plain")
                .putExtra(Intent.EXTRA_TEXT, getShareUrl()), getString(R.string.share)));
        break;
    case R.id.action_open_in_browser:
        AppCustomTabsKt.launchChromeCustomTabs(this, getShareUrl());
        break;
    case R.id.action_create_follow:
        throwableFunc = () -> twitter.createFriendship(user.getId());
        didAction = R.string.did_follow;
        break;
    case R.id.action_destroy_follow:
        throwableFunc = () -> twitter.destroyFriendship(user.getId());
        didAction = R.string.did_unfollow;
        break;
    case R.id.action_create_mute:
        throwableFunc = () -> twitter.createMute(user.getId());
        didAction = R.string.did_mute;
        break;
    case R.id.action_destroy_mute:
        throwableFunc = () -> twitter.destroyMute(user.getId());
        didAction = R.string.did_unmute;
        break;
    case R.id.action_create_block:
        throwableFunc = () -> twitter.createBlock(user.getId());
        didAction = R.string.did_block;
        break;
    case R.id.action_destroy_block:
        throwableFunc = () -> twitter.destroyBlock(user.getId());
        didAction = R.string.did_unblock;
        break;
    case R.id.action_destroy_follow_follower:
        throwableFunc = () -> {
            twitter.createBlock(user.getId());
            twitter.destroyBlock(user.getId());
        };
        didAction = R.string.did_destroy_ff;
        break;
    case R.id.action_spam_report:
        throwableFunc = () -> GlobalApplication.twitter.reportSpam(user.getId());
        break;
    }

    if (throwableFunc != null && didAction != -1) {
        ThrowableFunc finalThrowableFunc = throwableFunc;
        int finalDidAction = didAction;
        confirmDialog(item.getTitle(), getString(R.string.confirm_message),
                () -> runAsWorkerThread(finalThrowableFunc, finalDidAction));
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.happy_coding.viralo.twitter.FriendFollower.java

License:Apache License

/**
 * Unfollows the contact./*w w  w  . ja  v a  2  s . c om*/
 *
 * @param myContact
 * @return
 */
public Boolean unfollow(Contact myContact) {

    Twitter twitter = new TwitterFactory().getInstance();
    try {
        logger.debug("remove friendship for " + myContact.getUid());
        twitter.destroyFriendship(myContact.getUid());
    } catch (TwitterException e) {
        logger.error("can't unfollow contact " + myContact.getUid(), e);
        return Boolean.FALSE;
    }
    return Boolean.TRUE;
}

From source file:com.javielinux.utils.UserActions.java

License:Apache License

public static InfoUsers goToChangeRelationship(Context context, InfoUsers infoUsers, InfoUsers.Friend friend) {
    ConnectionManager.getInstance().open(context);
    Twitter twitter = ConnectionManager.getInstance().getTwitter(DBUtils.getIdFromUserName(friend.user));
    try {//w w w. jav a 2  s  .c  o m
        if (friend.follower) {
            twitter.destroyFriendship(infoUsers.getName());
            friend.follower = false;
        } else {
            twitter.createFriendship(infoUsers.getName());
            friend.follower = true;
        }
        infoUsers.replaceFriendly(friend.user, friend);
        return infoUsers;
    } catch (TwitterException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:it.greenvulcano.gvesb.social.twitter.directcall.TwitterOperationDisableNotification.java

License:Open Source License

@Override
public void execute(SocialAdapterAccount account) throws SocialAdapterException {
    try {/*from w  ww .  j av  a  2  s  .  com*/
        Twitter twitter = (Twitter) account.getProxyObject();
        try {
            long id = Long.parseLong(fromAccountId);
            user = twitter.destroyFriendship(id);
        } catch (NumberFormatException exc) {
            user = twitter.destroyFriendship(fromAccountId);
        }
    } catch (NumberFormatException exc) {
        logger.error("Call to TwitterOperationDisableNotification failed. Check fromAccountId[" + fromAccountId
                + "] format.", exc);
        throw new SocialAdapterException(
                "Call to TwitterOperationDisableNotification failed. Check fromAccountId[" + fromAccountId
                        + "] format.",
                exc);
    } catch (TwitterException exc) {
        logger.error("Call to TwitterOperationDisableNotification fromAccountId[" + fromAccountId + "] failed.",
                exc);
        throw new SocialAdapterException(
                "Call to TwitterOperationDisableNotification fromAccountId[" + fromAccountId + "] failed.",
                exc);
    }
}

From source file:kerguelenpetrel.UnfriendSomeoneServlet.java

License:Apache License

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    User unfriend = null;/*from w  w w  .j av a 2 s  .c  o m*/
    Random r = new Random();

    resp.setContentType("text/plain; charset=UTF-8");
    try {
        //Get the Twitter object
        Twitter twit = TwitterFactory.getSingleton();

        //Find a friend of a follower to bother
        long[] followerIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs();
        if (followerIDs.length == 0) {
            resp.getWriter().println("No friends to unfollow");
            return;
        }
        unfriend = twit.showUser(followerIDs[r.nextInt(followerIDs.length)]);
        twit.destroyFriendship(unfriend.getId());
        resp.getWriter().println("Successfully unfollowed @" + unfriend.getScreenName());
        resp.getWriter().println("\n");
    } catch (TwitterException e) {
        resp.getWriter().println("Problem with Twitter \n");
        e.printStackTrace(resp.getWriter());
    } catch (Exception e) {
        resp.getWriter().println("Problem! \n");
        e.printStackTrace(resp.getWriter());
    }
}

From source file:twitter4j.examples.friendship.DestroyFriendship.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.DestroyFriendship [screen name]
 *
 * @param args message//w w  w  .j  a v  a  2  s  . c om
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.friendship.DestroyFriendship [screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        twitter.destroyFriendship(args[0]);
        System.out.println("Successfully unfollowed [" + args[0] + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to unfollow: " + te.getMessage());
        System.exit(-1);
    }
}