Example usage for twitter4j IDs getIDs

List of usage examples for twitter4j IDs getIDs

Introduction

In this page you can find the example usage for twitter4j IDs getIDs.

Prototype

long[] getIDs();

Source Link

Usage

From source file:com.dhamacher.sentimentanalysis4tweets.twitterapi.TweetOperator.java

License:Apache License

public LinkedList<Long> getRetweetedByIds(long id) {
    int page = 1;
    IDs ids;
    LinkedList<Long> res = new LinkedList<Long>();
    try {//from   ww  w  .  ja v  a 2 s  . com
        do {
            ids = twitter.getIncomingFriendships(id);/*getRetweetedByIDs(id, new Paging(page, 100));*/
            for (long this_id : ids.getIDs()) {
                res.add(this_id);
            }
            ++page;
        } while (ids.getIDs().length != 0);

    } catch (TwitterException ex) {
        Logger.getLogger(TweetOperator.class.getName()).log(Level.SEVERE, null, ex);
    }
    return res;
}

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

License:Open Source License

public TwitterDTO checkAlreadyFriend(TwitterDTO twitterDTO) {
    String friendScreenName = null;
    int friendId = 0;
    AccessToken accessToken = (AccessToken) twitterDTO.getAccessToken();
    twitter.setOAuthAccessToken(accessToken);
    friendScreenName = twitterDTO.getUserScreeName();
    try {//from w  ww. ja va 2 s .  com
        twitterDTO = new TwitterDTO();
        User profile = twitter.showUser(friendScreenName);
        friendId = profile.getId();
        IDs friendsIds = twitter.getFriendsIDs();
        int i = 0;
        if (friendsIds != null) {
            for (int userId : friendsIds.getIDs()) {

                if (userId == friendId) {
                    twitterDTO.setAlreadyFriends(true);
                }
            }
        }

        IDs followersIds = twitter.getFollowersIDs();
        if (followersIds != null) {
            for (int userId : followersIds.getIDs()) {
                i++;
                System.out.println(i + " - " + userId + " Already you are follwoing !");

                fetchProfile(twitter.showUser(userId), twitterDTO);

                if (userId == friendId) {
                    System.out.println(friendId + " Friend is following you !");
                    twitterDTO.setFriendIsFollowing(true);
                }
            }
        }
    } catch (TwitterException e) {
        e.printStackTrace();
    }

    return twitterDTO;
}

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

License:Open Source License

private List getFollowersProfile(Twitter twitterClient, String screenName, TwitterDTO twitterDTO)
        throws BaseAppException {
    //ProfileDTO profileDTO = null;
    User profile = null;//from w ww .  j av  a  2s .  c o m
    List followersList = null;

    try {
        followersList = new ArrayList();
        int i = 0;
        IDs friendsIds = twitterClient.getFollowersIDs(screenName);

        if (friendsIds != null) {
            for (int userId : friendsIds.getIDs()) {
                //if(i<5){
                profile = twitterClient.showUser(userId);

                twitterDTO = fetchProfile(profile, twitterDTO);
                followersList.add(twitterDTO);
            }
            //i++;

            //}
        }

    } catch (TwitterException e) {

        processTwitterException(e);
    }

    return followersList;
}

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

License:Open Source License

private List getFriendsProfile(Twitter twitterClient, String screenName, TwitterDTO twitterDTO)
        throws BaseAppException {
    //ProfileDTO profileDTO = null;
    User profile = null;/*  w  w  w .  ja v a  2 s .  c o m*/
    List friendsList = null;

    try {
        friendsList = new ArrayList();

        IDs friendsIds = twitterClient.getFriendsIDs(screenName);
        int i = 0;
        if (friendsIds != null) {
            for (int userId : friendsIds.getIDs()) {
                //if(i<5){
                profile = twitterClient.showUser(userId);

                twitterDTO = fetchProfile(profile, twitterDTO);
                friendsList.add(twitterDTO);
            }
            //i++;

            //}
        }

    } catch (TwitterException e) {

        processTwitterException(e);
    }

    return friendsList;
}

From source file:com.freshdigitable.udonroad.subscriber.ConfigRequestWorker.java

License:Apache License

private Observable<TreeSet<Long>> fetchAllIgnoringUsers() {
    return Observable.concat(twitterApi.getAllMutesIDs(), twitterApi.getAllBlocksIDs())
            .map(new Func1<IDs, long[]>() {
                @Override//from   www  .j av  a2s.  c  o m
                public long[] call(IDs iDs) {
                    return iDs.getIDs();
                }
            }).collect(new Func0<TreeSet<Long>>() {
                @Override
                public TreeSet<Long> call() {
                    return new TreeSet<>();
                }
            }, new Action2<TreeSet<Long>, long[]>() {
                @Override
                public void call(TreeSet<Long> collector, long[] ids) {
                    for (long l : ids) {
                        collector.add(l);
                    }
                }
            }).observeOn(AndroidSchedulers.mainThread()).doOnNext(new Action1<Collection<Long>>() {
                @Override
                public void call(Collection<Long> ids) {
                    cache.replaceIgnoringUsers(ids);
                }
            }).doOnError(onErrorAction);
}

From source file:com.freshdigitable.udonroad.TimelineInstTestBase.java

License:Apache License

protected void setupConfig(User loginUser) throws Exception {
    final TwitterAPIConfiguration twitterAPIConfigMock = TwitterResponseMock.createTwitterAPIConfigMock();
    when(twitter.getAPIConfiguration()).thenReturn(twitterAPIConfigMock);

    final long userId = loginUser.getId();
    when(twitter.getId()).thenReturn(userId);
    when(twitter.showUser(userId)).thenReturn(loginUser);
    when(twitter.verifyCredentials()).thenReturn(loginUser);

    final IDs ignoringUserIDsMock = mock(IDs.class);
    when(ignoringUserIDsMock.getIDs()).thenReturn(new long[0]);
    when(ignoringUserIDsMock.getNextCursor()).thenReturn(0L);
    when(ignoringUserIDsMock.getPreviousCursor()).thenReturn(0L);
    when(twitter.getBlocksIDs()).thenReturn(ignoringUserIDsMock);
    when(twitter.getBlocksIDs(anyLong())).thenReturn(ignoringUserIDsMock);
    when(twitter.getMutesIDs(anyLong())).thenReturn(ignoringUserIDsMock);
}

From source file:com.google.appinventor.components.runtime.Twitter.java

License:Open Source License

/**
 * Gets who is following you.//from  w  w w .j  a  va 2  s.  c  om
 */
@SimpleFunction
public void RequestFollowers() {
    if (twitter == null || userName.length() == 0) {
        form.dispatchErrorOccurredEvent(this, "RequestFollowers",
                ErrorMessages.ERROR_TWITTER_REQUEST_FOLLOWERS_FAILED, "Need to login?");
        return;
    }
    AsynchUtil.runAsynchronously(new Runnable() {
        List<User> friends = new ArrayList<User>();

        public void run() {
            try {
                IDs followerIDs = twitter.getFollowersIDs(-1);
                for (long id : followerIDs.getIDs()) {
                    // convert from the IDs returned to the User
                    friends.add(twitter.showUser(id));
                }
            } catch (TwitterException e) {
                form.dispatchErrorOccurredEvent(Twitter.this, "RequestFollowers",
                        ErrorMessages.ERROR_TWITTER_REQUEST_FOLLOWERS_FAILED, e.getMessage());
            } finally {
                handler.post(new Runnable() {
                    public void run() {
                        followers.clear();
                        for (User user : friends) {
                            followers.add(user.getName());
                        }
                        FollowersReceived(followers);
                    }
                });
            }
        }
    });
}

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

License:Apache License

/**
 * Returns the friends for the provided friend.
 *
 * @param forContact//www. jav a 2  s  . c o m
 * @return
 */
public List<Contact> findFriends(Contact forContact) {

    List<Contact> contacts = new ArrayList<Contact>();
    Twitter twitter = new TwitterFactory().getInstance();

    try {
        IDs list = twitter.getFriendsIDs(forContact.getUid(), -1);
        do {

            for (long id : list.getIDs()) {
                Contact contact = new Contact(id);
                contact.setActiveUid(twitter.getId());
                contacts.add(contact);
            }
        } while (list.hasNext());

    } catch (TwitterException e) {
        logger.error("can't find friends for contact", e);
        return null;
    }
    return contacts;
}

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

License:Apache License

/**
 * Returns a list of contacts which follow the provided contact.
 *
 * @param forContact//ww  w  . j  a v a 2 s.  com
 * @return
 */
public List<Contact> findFollowers(Contact forContact) {
    List<Contact> contacts = new ArrayList<Contact>();
    Twitter twitter = new TwitterFactory().getInstance();
    try {
        IDs list = twitter.getFollowersIDs(forContact.getUid(), -1);
        do {

            for (long id : list.getIDs()) {
                logger.debug("follower id: " + id);
                Contact contact = new Contact(id);
                contact.setActiveUid(twitter.getId());
                contacts.add(contact);
            }
        } while (list.hasNext());
    } catch (TwitterException e) {
        logger.error("can't find followers", e);
        return null;
    }
    return contacts;
}

From source file:com.itbs.aimcer.commune.twitter.TwitterConnection.java

License:Open Source License

private void getList() throws TwitterException {
    Group lastGroup;//from   w  w w.ja  va 2 s.  c om
    Contact contact;
    getGroupList().add(lastGroup = getGroupFactory().create(GROUP));
    lastGroup.clear(this); // b/c of reconnect
    IDs followersIDs = connection.getFollowersIDs(connection.getId());
    ResponseList<User> users = connection.lookupUsers(followersIDs.getIDs());
    for (User user : users) {
        contact = getContactFactory().create(user.getName(), this);
        lastGroup.add(contact);
    } // while
}