Example usage for twitter4j Relationship isSourceFollowedByTarget

List of usage examples for twitter4j Relationship isSourceFollowedByTarget

Introduction

In this page you can find the example usage for twitter4j Relationship isSourceFollowedByTarget.

Prototype

boolean isSourceFollowedByTarget();

Source Link

Document

Checks if source user is being followed by target user

Usage

From source file:MainActivity.java

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed

    try {//from w w  w .j a va 2 s .com

        Relationship r = twitter.showFriendship(uu1.getText(), uu2.getText());
        String s = r.getSourceUserScreenName() + " is ";
        if (r.isSourceFollowingTarget()) {

            s = s + " following " + r.getTargetUserScreenName();
            if (r.isSourceFollowedByTarget()) {
                s = s + " aslo " + r.getSourceUserScreenName() + " is followed by "
                        + r.getTargetUserScreenName();
            } else {
                s = s + " but " + r.getSourceUserScreenName() + " is not followed by "
                        + r.getTargetUserScreenName();
            }

        } else {

            s = s + " not following " + r.getTargetUserScreenName();

            if (r.isSourceFollowedByTarget()) {

                s = s + " interestingly " + r.getSourceUserScreenName() + " is followed by "
                        + r.getTargetUserScreenName();
            } else {
                s = s + " neither  " + r.getSourceUserScreenName() + " is followed by "
                        + r.getTargetUserScreenName();
            }

        }

        if (r.isSourceNotificationsEnabled()) {
            s = s + ", " + r.getSourceUserScreenName() + " has enabled notification for "
                    + r.getTargetUserScreenName();

        } else {
            s = s + ", " + r.getSourceUserScreenName() + " has no intention of enabling notification for "
                    + r.getTargetUserScreenName();
        }

        if (r.isSourceBlockingTarget()) {
            s = s + " its strange but " + r.getSourceUserScreenName() + " is blocking "
                    + r.getTargetUserScreenName();

        } else {
            s = s + " needless to say " + r.getSourceUserScreenName() + " is not blocking "
                    + r.getTargetUserScreenName();
        }

        u1.setText(s);

        // TODO add your handling code here:
    } catch (TwitterException ex) {
        Logger.getLogger(MainActivity.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ShowFriendshi.java

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.ShowFriendship  [source screen name] [target screen name]
 *
 * @param args message/*from w  w w . j  a  va  2s .  com*/
 */
public ArrayList<Long> showFriendship() {
    GetFriendsIDs getFriendsId = new GetFriendsIDs();
    ArrayList<Long> target = getFriendsId.getFriendsId();
    ArrayList<Long> filteredTarget = new ArrayList<Long>();
    Collections.shuffle(target);
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        int authenticatedUserId = (int) twitter.getId();
        if (target.size() < 50) {

            for (int i = 0; i < target.size(); i++) {
                Relationship relationship = twitter.showFriendship(authenticatedUserId, target.get(i));
                if (!relationship.isSourceFollowedByTarget()) {

                    filteredTarget.add(target.get(i));
                }

            }

        } else {
            for (int i = 0; i < 50; i++) {
                Relationship relationship = twitter.showFriendship(authenticatedUserId, target.get(i));
                if (!relationship.isSourceFollowedByTarget()) {

                    filteredTarget.add(target.get(i));
                }

            }

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

    }

    return filteredTarget;
}

From source file:com.javielinux.infos.InfoUsers.java

License:Apache License

public void checkFriend(Context context, String name) {
    if (!hasFriendly(name)) {
        addFriendly(name);//  w ww .  j a  va  2s  .c om
    }
    if (!isCheckFriendly(name)) {
        Friend friend = friendly.get(name);
        try {
            //Entity ent = DataFramework.getInstance().getTopEntity("users", "name = '"+getName()+"'", "");
            ConnectionManager.getInstance().open(context);
            Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();
            Relationship relationship = twitter.showFriendship(getName(), name);
            friend.friend = relationship.isSourceFollowingTarget();
            friend.follower = relationship.isSourceFollowedByTarget();
            friend.checked = true;
            friendly.remove(name);
            friendly.put(name, friend);
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    }
}

From source file:com.michaelfitzmaurice.clocktwerk.apps.FollowChecker.java

License:Apache License

public static void main(String[] args) throws Exception {

    String source = args[0];/*from w ww .  java2  s  .  c om*/
    String target = args[1];

    LOG.info("Setting up Twitter client...");
    Twitter twitter = new TwitterFactory().getInstance();
    LOG.info("Twitter client connected");

    LOG.info("Inspecting Twitter relationship between {} and {} ", source, target);
    Relationship relationship = twitter.showFriendship(source, target);
    boolean targetFollowsSource = relationship.isSourceFollowedByTarget();
    boolean sourceFollowsTarget = relationship.isSourceFollowingTarget();

    LOG.info("{} follows {}: {}", new Object[] { target, source, targetFollowsSource });
    LOG.info("{} follows {}: {}", new Object[] { source, target, sourceFollowsTarget });
}

From source file:com.SocialAccess.TwitterSearch.java

public static String[] FriendshipStatus(String[] args) {

    if (args.length < 2) {
        System.out.println("Usage: [source screen name] [target screen name]");
        System.exit(-1);/*  www .j  a va  2s .c om*/
    }

    String[] lineConnection = new String[2];
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Relationship relationship = twitter.showFriendship(args[0], args[1]);

        lineConnection[0] = args[0] + " is followed by " + args[1] + " "
                + relationship.isSourceFollowedByTarget();
        lineConnection[1] = args[0] + " is following " + args[1] + " " + relationship.isSourceFollowingTarget();

    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show friendship: " + te.getMessage());
        System.exit(-1);
    }
    return lineConnection;
}

From source file:net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment.java

License:Open Source License

private void updateRelationship(Activity activity, final long userId) {
    MainActivity mainActivity = (MainActivity) activity;
    Account account = mainActivity.getCurrentAccount();
    Twitter twitter = new TwitterApi(account).getTwitter();
    if (userId == account.userID) {
        textViewFollowed.setText(R.string.user_detail_followed_is_me);
        buttonFollow.setVisibility(View.GONE);
    } else {/*from  ww w  .  j  a  v  a 2  s .c o  m*/
        int theme = mainActivity.getThemeIndex();
        lockFollowButton(activity);
        textViewFollowed.setText(R.string.user_detail_loading);
        final Drawable red = Themes.getStyledDrawable(activity, theme, R.attr.button_round_red);
        final Drawable blue = Themes.getStyledDrawable(activity, theme, R.attr.button_round_blue);
        new ShowFriendshipTask(twitter, userId) {
            @Override
            protected void onPostExecute(Relationship relationship) {
                if (relationship != null) {
                    boolean isFollowing = relationship.isSourceFollowingTarget();
                    boolean isFollowed = relationship.isSourceFollowedByTarget();
                    setFollowButtonState(isFollowing, red, blue);
                    textViewFollowed.setText(
                            isFollowed ? R.string.user_detail_followed : R.string.user_detail_not_followed);
                }
            }
        }.execute();
    }
}

From source file:org.getlantern.firetweet.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues createCachedRelationship(final Relationship relationship, final long accountId) {
    final ContentValues values = new ContentValues();
    values.put(CachedRelationships.ACCOUNT_ID, accountId);
    values.put(CachedRelationships.USER_ID, relationship.getTargetUserId());
    values.put(CachedRelationships.FOLLOWING, relationship.isSourceFollowingTarget());
    values.put(CachedRelationships.FOLLOWED_BY, relationship.isSourceFollowedByTarget());
    values.put(CachedRelationships.BLOCKING, relationship.isSourceBlockingTarget());
    values.put(CachedRelationships.BLOCKED_BY, relationship.isSourceBlockedByTarget());
    values.put(CachedRelationships.MUTING, relationship.isSourceMutingTarget());
    return values;
}

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

License:Apache License

/**
 * Usage: java twitter4j.examples.friendship.ShowFriendship  [source screen name] [target screen name]
 *
 * @param args message/*from   w  w w.j a  va  2 s.  co  m*/
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println(
                "Usage: java twitter4j.examples.friendship.ShowFriendship [source screen name] [target screen name]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        Relationship relationship = twitter.showFriendship(args[0], args[1]);
        System.out.println("isSourceBlockingTarget: " + relationship.isSourceBlockingTarget());
        System.out.println("isSourceFollowedByTarget: " + relationship.isSourceFollowedByTarget());
        System.out.println("isSourceFollowingByTarget: " + relationship.isSourceFollowingTarget());
        System.out.println("isSourceNotificationsEnabled: " + relationship.isSourceNotificationsEnabled());
        System.out.println("canSourceDm: " + relationship.canSourceDm());
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to show friendship: " + te.getMessage());
        System.exit(-1);
    }
}