Example usage for twitter4j Status getUser

List of usage examples for twitter4j Status getUser

Introduction

In this page you can find the example usage for twitter4j Status getUser.

Prototype

User getUser();

Source Link

Document

Return the user associated with the status.
This can be null if the instance is from User.getStatus().

Usage

From source file:com.epsi.wks.api_wks_back.User.java

@GET
@Path("/following/tweet")
@Produces("application/json")
public List<JSONObject> getUserFollowingsTweets(@PathParam("id") long userID) {
    Twitter twitter = UtilConfig.getTwitterInstance();

    List<JSONObject> followingTweet = new ArrayList<>();
    try {/*from  w ww  .  j  a  va  2s  .c om*/
        PagableResponseList<twitter4j.User> userList = twitter.getFriendsList(userID, -1);

        for (twitter4j.User us : userList) {
            List<Status> statusFollower = twitter.getUserTimeline(us.getId());
            for (Status sts : statusFollower) {
                JSONObject tweet = new JSONObject();
                tweet.put("id", sts.getId());
                tweet.put("text", sts.getText());
                tweet.put("screen_name", sts.getUser().getScreenName());
                tweet.put("name", sts.getUser().getName());
                tweet.put("image_url", sts.getUser().getProfileImageURL());
                followingTweet.add(tweet);
            }
        }
    } catch (TwitterException e) {
    }
    System.out.println("array" + String.valueOf(followingTweet.size()));
    return followingTweet;
}

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

License:Open Source License

public List tweets(Twitter twitter, String screenName, TwitterDTO twitterDTO) throws BaseAppException {
    List tweetList = new ArrayList();

    List<Status> statuses = null;

    Paging paging = new Paging(1, 10);

    try {//w ww .j  a v  a 2 s  .c o  m
        statuses = twitter.getUserTimeline(screenName, paging);
    } catch (TwitterException e) {
        processTwitterException(e);
    }
    int i = 1;
    if (!statuses.isEmpty()) {

        for (Status status : statuses) {
            if (i <= 10) {
                User user = status.getUser();
                twitterDTO = new TwitterDTO();
                //   
                //   if(userId==status.getUser().getId()){
                if (status.getId() != 0) {
                    System.out.println(i + "TweetId=> " + status.getId());
                    twitterDTO.setTweetId(String.valueOf(status.getId()));
                }
                if (user.getProfileImageURL() != null) {
                    twitterDTO.setUserImg(user.getProfileImageURL().toString());
                }
                if (user.getScreenName() != null) {
                    twitterDTO.setUserScreeName("http://twitter.com/" + user.getScreenName());
                }
                if (user.getName() != null) {
                    twitterDTO.setUserName(user.getName());
                }
                if (status.getText() != null) {
                    twitterDTO.setTweet(status.getText());
                }
                System.out.println(status.getId() + " : " + status.getCreatedAt() + " >> " + status.getText());
                tweetList.add(twitterDTO);
                i++;
            } else {
                break;
            }

        }

    }

    return tweetList;
}

From source file:com.example.leonid.twitterreader.Twitter.TwitterGetTweets.java

License:Apache License

@Override
protected List<CreateTweet> doInBackground(String... params) {
    mTweetsInfo = new ArrayList<>();
    List<String> texts = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    List<String> images = new ArrayList<>();
    List<String> date = new ArrayList<>();
    if (!isCancelled()) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(ACCESS_KEY).setOAuthAccessTokenSecret(ACCESS_SECRET);
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        //query search result
        Query query = new Query(params[0]);
        //how much tweets need to be displayed(max 200)
        query.count(200);//from w  w  w. j a va2 s  . c  om
        try {
            mResult = twitter.search(query);
            for (twitter4j.Status status : mResult.getTweets()) {
                if (!isCancelled()) {
                    texts.add(status.getText());
                    titles.add(status.getUser().getName());
                    images.add(status.getUser().getBiggerProfileImageURL());
                    String cleanDate = status.getCreatedAt().toString();
                    date.add(cleanDate.substring(0, cleanDate.length() - 15) + " "
                            + cleanDate.substring(cleanDate.length() - 4));
                }
            }
        } catch (TwitterException e) {
            Log.e("exeption", e.toString());
        }
        //loop teuth results and create array list for list view
        for (int i = 0; i < texts.size(); i++) {
            mTweetsInfo.add(new CreateTweet(titles.get(i), images.get(i), texts.get(i), date.get(i)));
        }

    }
    return mTweetsInfo;
}

From source file:com.firewallid.commentwrapper.TwitterComment.java

public Map<String, String> formatOutput(Tuple3<Status, Status, Integer> statusComment, Status statusBase) {
    Status statusChild = statusComment._1();
    Status statusParent = statusComment._2();

    Map<String, String> comment = new HashMap<>();
    comment.put("id", String.valueOf(statusChild.getId()));
    comment.put("text", statusChild.getText());
    comment.put("userId", String.valueOf(statusChild.getUser().getId()));
    comment.put("userName", statusChild.getUser().getName());
    comment.put("userScreenName", statusChild.getUser().getScreenName());
    comment.put("time", String.valueOf(statusChild.getCreatedAt().getTime()));
    comment.put("replytoId", String.valueOf(statusParent.getId()));
    comment.put("replytoUserId", String.valueOf(statusParent.getUser().getId()));
    comment.put("replytoUserScreenName", statusParent.getUser().getScreenName());
    comment.put("depth", String.valueOf(statusComment._3()));
    comment.put("baseId", String.valueOf(statusBase.getId()));
    comment.put("baseUserId", String.valueOf(statusBase.getUser().getId()));
    comment.put("baseUserScreenName", statusBase.getUser().getScreenName());

    LOG.info(Joiner.on(". ").withKeyValueSeparator(":").join(comment));

    return comment;
}

From source file:com.firewallid.crawling.TwitterApp.java

public List<Status> replyTo(Status status) {
    String userScreenName = status.getUser().getScreenName();
    String date = new SimpleDateFormat("YYYY-MM-DD").format(status.getCreatedAt());
    Query query = new Query("to:" + userScreenName + " since:" + date);
    List<Status> repliesAll = new ArrayList<>();

    while (query != null) {
        QueryResult result = search(query);

        List<Status> replies = result.getTweets().parallelStream()
                /* Only reply to status's id*/
                .filter(tweet -> tweet.getInReplyToStatusId() == status.getId()).collect(Collectors.toList());

        repliesAll.addAll(replies);/* w w  w  . j  a v  a 2  s.co  m*/
        query = result.nextQuery();
    }

    return repliesAll;
}

From source file:com.firewallid.crawling.TwitterStreaming.java

public JavaPairDStream<String, Map<String, String>> streaming(JavaStreamingContext jsc) {
    /* Twitter Application */
    System.setProperty("twitter4j.oauth.consumerKey", conf.get(CONSUMER_KEY));
    System.setProperty("twitter4j.oauth.consumerSecret", conf.get(CONSUMER_SECRET));
    System.setProperty("twitter4j.oauth.accessToken", conf.get(ACCESS_TOKEN));
    System.setProperty("twitter4j.oauth.accessTokenSecret", conf.get(ACCESS_TOKEN_SECRET));

    JavaPairDStream<String, Map<String, String>> crawl = TwitterUtils
            /* Streaming */
            .createStream(jsc)/*from ww w  .  j  a  v a  2s  .  c om*/
            /* Indonesia language filtering */
            .filter((Status status) -> idLanguageDetector.detect(status.getText()))
            /* Collect data */
            .mapToPair((Status status) -> {
                Map<String, String> columns = new HashMap<>();
                columns.put("text", status.getText());
                columns.put("date", String.valueOf(status.getCreatedAt().getTime()));
                columns.put("screenName", status.getUser().getScreenName());
                columns.put("userName", status.getUser().getName());
                columns.put("userId", String.valueOf(status.getUser().getId()));

                LOG.info(String.format("id: %s. %s", status.getId(),
                        Joiner.on(". ").withKeyValueSeparator(": ").join(columns)));

                return new Tuple2<String, Map<String, String>>(String.valueOf(status.getId()), columns);
            });

    return crawl;
}

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

License:Apache License

@Override
public void bindStatus(final Status status) {
    super.bindStatus(status);
    if (status.isRetweet()) {
        bindRtUser(status.getUser());
    }/*from   w  w w . j a va  2  s  .co m*/

    final Status quotedBindingStatus = getBindingStatus(status).getQuotedStatus();
    if (quotedBindingStatus != null) {
        quotedStatus.bindStatus(quotedBindingStatus);
        quotedStatus.setVisibility(VISIBLE);
    }
}

From source file:com.freshdigitable.udonroad.module.realm.StatusCacheRealm.java

License:Apache License

@NonNull
private Collection<Status> splitUpsertingStatus(Collection<Status> statuses) {
    final LinkedHashMap<Long, Status> updates = new LinkedHashMap<>();
    for (Status s : statuses) {
        if (!configStore.isIgnoredUser(s.getUser().getId())) {
            updates.put(s.getId(), s);/*from   w  ww. j  a v a 2 s  . c om*/
        }
        final Status quotedStatus = s.getQuotedStatus();
        if (quotedStatus != null && !configStore.isIgnoredUser(quotedStatus.getUser().getId())) {
            updates.put(quotedStatus.getId(), quotedStatus);
        }
        final Status retweetedStatus = s.getRetweetedStatus();
        if (retweetedStatus != null && !configStore.isIgnoredUser(retweetedStatus.getUser().getId())) {
            updates.put(retweetedStatus.getId(), retweetedStatus);
            final Status rtQuotedStatus = retweetedStatus.getQuotedStatus();
            if (rtQuotedStatus != null && !configStore.isIgnoredUser(rtQuotedStatus.getUser().getId())) {
                updates.put(rtQuotedStatus.getId(), rtQuotedStatus);
            }
        }
    }
    return updates.values();
}

From source file:com.freshdigitable.udonroad.module.realm.StatusCacheRealm.java

License:Apache License

private Collection<User> splitUpsertingUser(Collection<Status> updates) {
    Map<Long, User> res = new LinkedHashMap<>(updates.size());
    for (Status s : updates) {
        final User user = s.getUser();
        res.put(user.getId(), user);// w  ww.j av a 2s.c  o m
    }
    return res.values();
}

From source file:com.freshdigitable.udonroad.module.realm.StatusRealm.java

License:Apache License

StatusRealm(Status status) {
    this.id = status.getId();
    this.createdAt = status.getCreatedAt();
    this.retweetedStatus = status.getRetweetedStatus();
    this.retweet = status.isRetweet();
    if (status.isRetweet()) {
        this.retweetedStatusId = this.retweetedStatus.getId();
    }/*from  ww w .  j a  v a  2  s  .  c o  m*/
    this.text = status.getText();
    this.source = status.getSource();
    this.retweetCount = status.getRetweetCount();
    this.favoriteCount = status.getFavoriteCount();
    this.reaction = new StatusReactionImpl(status);
    this.user = status.getUser();
    this.userId = user.getId();
    this.urlEntities = URLEntityRealm.createList(status.getURLEntities());

    this.mediaEntities = new RealmList<>();
    final ExtendedMediaEntity[] me = status.getExtendedMediaEntities();
    for (ExtendedMediaEntity m : me) {
        mediaEntities.add(new ExtendedMediaEntityRealm(m));
    }
    final UserMentionEntity[] userMentionEntities = status.getUserMentionEntities();
    this.userMentionEntities = new RealmList<>();
    for (UserMentionEntity u : userMentionEntities) {
        this.userMentionEntities.add(new UserMentionEntityRealm(u));
    }

    this.quotedStatus = status.getQuotedStatus();
    this.quotedStatusId = status.getQuotedStatusId();
}