Example usage for twitter4j Twitter createFriendship

List of usage examples for twitter4j Twitter createFriendship

Introduction

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

Prototype

User createFriendship(long userId) throws TwitterException;

Source Link

Document

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

Usage

From source file:CreateFriendship.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.CreateFriendship [screen name]
 *
 * @param args message//w ww . ja va 2s. c o m
 */
public void Follow(ArrayList<String> args) {

    try {

        for (String values : args) {

            Twitter twitter = new TwitterFactory().getInstance();

            twitter.createFriendship(values);

        }
    } catch (TwitterException te) {

        System.out.println("Failed to follow: ");

    }
}

From source file:br.shura.team.mpsbot.venusext.FollowById.java

License:Open Source License

@Override
public void callVoid(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException {
    ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class);
    Twitter twitter = bot.getHandler();
    IntegerValue value = (IntegerValue) descriptor.get(0);

    Helper.execute(context, () -> twitter.createFriendship(value.value()));
}

From source file:br.shura.team.mpsbot.venusext.FollowByName.java

License:Open Source License

@Override
public void callVoid(Context context, FunctionCallDescriptor descriptor) throws ScriptRuntimeException {
    ConnectedBot bot = context.getApplicationContext().getUserData("bot", ConnectedBot.class);
    Twitter twitter = bot.getHandler();
    StringValue value = (StringValue) descriptor.get(0);

    Helper.execute(context, () -> twitter.createFriendship(value.value()));
}

From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java

License:Apache License

public void importFriends() {
    try {/*from  w  w  w.  j  av  a  2  s .c  o m*/
        Twitter twitter = getTwitterClient();
        UserService userService = ServiceFactory.newInstance().createUserService();
        boolean exists = true;
        long cursor = -1;

        while (exists) {
            //return 100 follower with status per request
            PagableResponseList<User> twitterFollowers = twitter.getFollowersStatuses(cursor);

            for (User user : twitterFollowers) {
                com.appspot.bitlyminous.entity.User entity = userService
                        .getUserByScreenName(user.getScreenName());
                if (entity == null) {
                    entity = new com.appspot.bitlyminous.entity.User();
                    entity.setScreenName(user.getScreenName());
                    entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER);
                    userService.updateUser(entity);
                    twitter.createFriendship(user.getScreenName());
                    twitter.sendDirectMessage(user.getScreenName(),
                            ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome"));
                    // following fofs will hit the limit soon.
                    //                   IDs friendsIDs = twitter.getFriendsIDs(user.getId());
                    //                   for (int id : friendsIDs.getIDs()) {
                    //                      twitter.createFriendship(id);
                    //                   }
                } else if (entity.getLevel() != com.appspot.bitlyminous.entity.User.Level.DIRECT_USER) {
                    entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER);
                    userService.updateUser(entity);
                    twitter.createFriendship(user.getScreenName());
                    twitter.sendDirectMessage(user.getScreenName(),
                            ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome"));
                    // following fofs will hit the limit soon.
                    //                   IDs friendsIDs = twitter.getFriendsIDs(user.getId());
                    //                   for (int id : friendsIDs.getIDs()) {
                    //                      twitter.createFriendship(id);
                    //                   }
                }
            }

            exists = twitterFollowers.hasNext();
            cursor = twitterFollowers.getNextCursor();
        }
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:com.eventattend.portal.bl.TwitterBL.java

License:Open Source License

public boolean followInTwitter(long userId, Twitter twitter) throws BaseAppException {
    User user = null;//from w w  w .  j  a  va2  s .c  o  m
    boolean result = false;
    try {

        user = twitter.createFriendship(String.valueOf(userId));
        result = true;
    } catch (TwitterException e) {
        processTwitterException(e);
    }
    return result;
}

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

License:Apache License

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ThrowableFunc throwableFunc = null;/*ww  w  . ja  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

/**
 * Follows the friends.// w ww . j a va  2s.  c o m
 *
 * @param myContact
 * @return
 */
public Boolean follow(Contact myContact) {
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        logger.debug("Create friendship for " + myContact.getUid());
        twitter.createFriendship(myContact.getUid());
    } catch (TwitterException e) {
        logger.error("Can't follow 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 {//from  w  ww . ja  v a2  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:com.twitstreet.twitter.AnnouncerMgrImpl.java

License:Open Source License

@Override
public void follow(long userId) {
    Twitter twitter = random();
    String screenName = "";
    try {/*from  w w w  .ja v  a  2 s  .  co m*/
        twitter.createFriendship(userId);
        screenName = twitter.getScreenName();
    } catch (TwitterException e) {
        logger.error("Error while following: " + userId + " Announcer: " + screenName, e);
    }
}

From source file:com.twitstreet.twitter.AnnouncerMgrImpl.java

License:Open Source License

@Override
public void followForDiabloBird(long userId) {
    Twitter twitter = diablobird;
    String screenName = "";
    try {//from   w  w  w .  j  a  va  2 s  .co m
        twitter.createFriendship(userId);
        screenName = twitter.getScreenName();
        logger.info("followForDiabloBird");
    } catch (TwitterException e) {
        logger.error("Error while following: " + userId + " Announcer: " + screenName, e);
    }
}