Example usage for twitter4j Status getHashtagEntities

List of usage examples for twitter4j Status getHashtagEntities

Introduction

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

Prototype

HashtagEntity[] getHashtagEntities();

Source Link

Document

Returns an array if hashtag mentioned in the tweet.

Usage

From source file:spout.Twitter.java

License:Apache License

@Override
public void nextTuple() {
    Status ret = queue.poll();
    if (ret == null) {
        Utils.sleep(50);//from   www.  jav a  2 s .co  m
    } else {

        Object[] values = new Object[this.fields.length];
        for (int i = 0; i < this.fields.length; i++) {
            if (this.fields[i].equalsIgnoreCase("place")) {
                values[i] = ret.getGeoLocation();
            } else if (this.fields[i].equalsIgnoreCase("retweet_count")) {
                values[i] = ret.getRetweetCount();
            } else if (this.fields[i].equalsIgnoreCase("text")) {
                values[i] = ret.getText();
            } else if (this.fields[i].equalsIgnoreCase("hashtags")) {
                values[i] = ret.getHashtagEntities();
            }

        }

        _collector.emit(new Values(values));

    }

}

From source file:storm.starter.spout.Q2FetchTweetSpout.java

License:Apache License

@Override
public void nextTuple() {
    //Utils.sleep(interval);
    Status ret = queue.poll();
    if (ret == null) {
        Utils.sleep(10);/*from  ww w . j a v a2 s  .com*/
    } else {
        System.out.println("DEBUG\tFetchTweetSpout\t" + ret.getText());
        if (ret.getLang().equals("en")) {
            Date date = new Date();
            long currTime = date.getTime();
            ArrayList<String> hss = new ArrayList<String>();
            for (HashtagEntity htentity : ret.getHashtagEntities()) {
                hss.add(htentity.getText());
            }
            tweetInfoList.add(new TweetInfo(ret.getUser().getFriendsCount(), hss, ret.getText()));

            if ((currTime - timestamp) > interval) {
                timestamp = currTime;
                sequenceNumber++;
                _collector.emit(new Values(sequenceNumber, tweetInfoList));
                tweetInfoList.clear();
            }
        }
    }
}

From source file:storm.starter.spout.Q2SeqTwitterSpout.java

License:Apache License

@Override
public void nextTuple() {
    Status ret = queue.poll();
    if (ret == null) {
        Utils.sleep(50);/* www  . j  a va  2s  . com*/
    } else {

        Date date = new Date();
        long currTime = date.getTime();
        ArrayList<String> hss = new ArrayList<String>();
        for (HashtagEntity htentity : ret.getHashtagEntities()) {
            hss.add(htentity.getText());
        }
        tweetInfoList.add(new TweetInfo(ret.getUser().getFriendsCount(), hss, ret.getText()));

        if ((currTime - timestamp) > interval) {
            if (tweetInfoList.size() > 0) {
                timestamp = currTime;
                sequenceNumber++;
                _collector.emit(new Values(sequenceNumber, tweetInfoList));
                tweetInfoList.clear();
            } else {
                System.out.println("DEBUG\tQ2SeqTweetSpout\tEmptyTupleFound\t" + ret.getText());
            }
        }
    }
}

From source file:testtweet.TweetUsingTwitter4jExample.java

/**
 * @param args the command line arguments
 *///w  ww.j a va 2 s .co  m
public static void main(String[] args) throws IOException, TwitterException {

    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory(Data.getConf().build());

    //Instantiate a new Twitter instance
    Twitter twitter = twitterFactory.getInstance();

    /*
    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);
            
    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
    */

    //Instantiate and initialize a new twitter status update
    StatusUpdate statusUpdate = new StatusUpdate(
            //your tweet or status message
            "Twitter API #Hacked");
    //attach any media, if you want to
    /*
    statusUpdate.setMedia(
    //title of media
    "http://h1b-work-visa-usa.blogspot.com"
    , new URL("http://lh6.ggpht.com/-NiYLR6SkOmc/Uen_M8CpB7I/AAAAAAAAEQ8/tO7fufmK0Zg/h-1b%252520transfer%252520jobs%25255B4%25255D.png?imgmax=800").openStream());
    */
    //tweet or update status
    Status status = twitter.updateStatus(statusUpdate);

    //response from twitter server
    System.out.println("status.toString() = " + status.toString());
    System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
    System.out.println("status.getSource() = " + status.getSource());
    System.out.println("status.getText() = " + status.getText());
    System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
    System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
    System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
    System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
    System.out.println("status.getId() = " + status.getId());
    System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
    System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
    System.out.println("status.getPlace() = " + status.getPlace());
    System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
    System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
    System.out.println("status.getUser() = " + status.getUser());
    System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
    System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
    System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
    if (status.getRateLimitStatus() != null) {
        System.out
                .println("status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
        System.out.println(
                "status.getRateLimitStatus().getRemaining() = " + status.getRateLimitStatus().getRemaining());
        System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                + status.getRateLimitStatus().getResetTimeInSeconds());
        System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                + status.getRateLimitStatus().getSecondsUntilReset());
        System.out.println("status.getRateLimitStatus().getRemainingHits() = "
                + status.getRateLimitStatus().getRemaining());
    }
    System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
    System.out.println("status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
}

From source file:twitterapidemo.TwitterAPIDemo.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {

    //TwitterAPIDemo twitterApiDemo = new TwitterAPIDemo();

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(consumerKey);
    builder.setOAuthConsumerSecret(consumerSecret);
    Configuration configuration = builder.build();

    TwitterFactory twitterFactory = new TwitterFactory(configuration);
    Twitter twitter = twitterFactory.getInstance();
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    Scanner sc = new Scanner(System.in);
    System.out.println(//  w  ww.j a  v  a 2 s  . c  o  m
            "Enter your choice:\n1. To post tweet\n2.To search tweets\n3. Recent top 3 trends and number of posts of each trending topic");
    int choice = sc.nextInt();
    switch (choice) {
    case 1:
        System.out.println("What's happening: ");
        String post = sc.next();
        StatusUpdate statusUpdate = new StatusUpdate(post + "-Posted by TwitterAPI");
        Status status = twitter.updateStatus(statusUpdate);

        System.out.println("status.toString() = " + status.toString());
        System.out.println("status.getInReplyToScreenName() = " + status.getInReplyToScreenName());
        System.out.println("status.getSource() = " + status.getSource());
        System.out.println("status.getText() = " + status.getText());
        System.out.println("status.getContributors() = " + Arrays.toString(status.getContributors()));
        System.out.println("status.getCreatedAt() = " + status.getCreatedAt());
        System.out.println("status.getCurrentUserRetweetId() = " + status.getCurrentUserRetweetId());
        System.out.println("status.getGeoLocation() = " + status.getGeoLocation());
        System.out.println("status.getId() = " + status.getId());
        System.out.println("status.getInReplyToStatusId() = " + status.getInReplyToStatusId());
        System.out.println("status.getInReplyToUserId() = " + status.getInReplyToUserId());
        System.out.println("status.getPlace() = " + status.getPlace());
        System.out.println("status.getRetweetCount() = " + status.getRetweetCount());
        System.out.println("status.getRetweetedStatus() = " + status.getRetweetedStatus());
        System.out.println("status.getUser() = " + status.getUser());
        System.out.println("status.getAccessLevel() = " + status.getAccessLevel());
        System.out.println("status.getHashtagEntities() = " + Arrays.toString(status.getHashtagEntities()));
        System.out.println("status.getMediaEntities() = " + Arrays.toString(status.getMediaEntities()));
        if (status.getRateLimitStatus() != null) {
            System.out.println(
                    "status.getRateLimitStatus().getLimit() = " + status.getRateLimitStatus().getLimit());
            System.out.println("status.getRateLimitStatus().getRemaining() = "
                    + status.getRateLimitStatus().getRemaining());
            System.out.println("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + status.getRateLimitStatus().getResetTimeInSeconds());
            System.out.println("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + status.getRateLimitStatus().getSecondsUntilReset());
        }
        System.out.println("status.getURLEntities() = " + Arrays.toString(status.getURLEntities()));
        System.out.println(
                "status.getUserMentionEntities() = " + Arrays.toString(status.getUserMentionEntities()));
        break;
    case 2:
        System.out.println("Enter keyword");
        String keyword = sc.next();
        try {
            Query query = new Query(keyword);
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    System.out.println(tweet.getCreatedAt() + ":\t@" + tweet.getUser().getScreenName() + " - "
                            + tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
            System.exit(0);
        } catch (TwitterException te) {
            System.out.println("Failed to search tweets: " + te.getMessage());
            System.exit(-1);
            break;
        }
    case 3:
        //WOEID for India = 23424848
        Trends trends = twitter.getPlaceTrends(23424848);
        int count = 0;
        for (Trend trend : trends.getTrends()) {
            if (count < 3) {
                Query query = new Query(trend.getName());
                QueryResult result;
                int numberofpost = 0;
                do {
                    result = twitter.search(query);
                    List<Status> tweets = result.getTweets();
                    for (Status tweet : tweets) {
                        numberofpost++;
                    }
                } while ((query = result.nextQuery()) != null);
                System.out
                        .println("Number of post for the topic '" + trend.getName() + "' is: " + numberofpost);
                count++;
            } else
                break;
        }
        break;
    default:
        System.out.println("Invalid input");
    }
}

From source file:twittermongodbapp.SaveTweets.java

static public void saveTweets(DB db, twitter4j.Twitter twitter) throws TwitterException {
    DBCollection collection = db.getCollection("collection2");
    DBCollection savedCollection = db.getCollection("savedCollection");
    DBCollection ConnectionCollection = db.getCollection(" ConnectionCollection");
    BasicDBObject document0 = new BasicDBObject();
    savedCollection.remove(document0);/*from w  w  w. j a va2 s  .co  m*/
    ConnectionCollection.remove(document0);
    Status savedTweet;

    //Read Tweets from Database
    System.out.println("Saved tweets: ");
    DBCursor cursor = collection.find();
    List<String> allUsers = new ArrayList<>();
    int count = 1;

    while (cursor.hasNext()) {
        DBObject obj = cursor.next();
        savedTweet = TwitterObjectFactory.createStatus(obj.toString());

        String name = savedTweet.getUser().getScreenName();
        String date = savedTweet.getCreatedAt().toString();
        boolean exist = false;

        BasicDBObject document = new BasicDBObject("User", name);
        BasicDBObject searchDocument = new BasicDBObject("User", name);
        DBObject theObj = null;

        if (!allUsers.contains(name)) {
            allUsers.add(name);
        } else {
            exist = true;
            DBCursor cursor2 = savedCollection.find(searchDocument);
            if (cursor2.hasNext()) {
                theObj = cursor2.next();
            }

        }

        // BasicDBList allHashtags = new BasicDBList();
        List<String> allHashtags = new ArrayList<>();
        List<String> allsortURLS = new ArrayList<>();
        List<String> allcompleteURLS = new ArrayList<>();
        //BasicDBList allURLS = new BasicDBList();
        List<String> allmentionedUsers = new ArrayList<>();
        List<String> allTweets = new ArrayList<>();

        if (exist) {
            allHashtags = (ArrayList) theObj.get("Hashtags");
        }
        HashtagEntity[] hashtagsEntities = savedTweet.getHashtagEntities();
        for (HashtagEntity hashtagsEntitie : hashtagsEntities) {
            if (!allHashtags.contains(hashtagsEntitie.getText())) {
                allHashtags.add(hashtagsEntitie.getText());
            }
            saveConnection(date, name, new BasicDBObject("hashtag", hashtagsEntitie.getText()), 1, count,
                    ConnectionCollection);
            count++;
        }
        document.append("Hashtags", allHashtags);

        if (exist) {
            allsortURLS = (ArrayList) theObj.get("sortUrls");
            allcompleteURLS = (ArrayList) theObj.get("completeUrls");
        }
        URLEntity[] urlEntities = savedTweet.getURLEntities();
        if (savedTweet.getURLEntities().length > 0) {
            for (int i = 0; i < savedTweet.getURLEntities().length; i++) {
                if (urlEntities[i].getStart() < urlEntities[i].getEnd()) {

                    BasicDBObject document1 = new BasicDBObject("url", urlEntities[i].getURL());
                    String completeURL = urlEntities[i].getExpandedURL();
                    document1.append("completeURL", completeURL);
                    if (!allsortURLS.contains(document1)) {
                        allsortURLS.add(urlEntities[i].getURL());
                        allcompleteURLS.add(urlEntities[i].getExpandedURL());
                    }
                    saveConnection(date, name, document1, 2, count, ConnectionCollection);
                    count++;
                }
            }
        }
        document.append("sortUrls", allsortURLS);
        document.append("completeUrls", allsortURLS);

        if (exist) {
            allmentionedUsers = (ArrayList) theObj.get("Mentions");
        }
        UserMentionEntity[] mentionEntities = savedTweet.getUserMentionEntities();
        for (UserMentionEntity mentionEntitie : mentionEntities) {
            BasicDBObject document2 = new BasicDBObject("mentioned_user", mentionEntitie.getText());
            if (!allmentionedUsers.contains(mentionEntitie.getText())) {
                allmentionedUsers.add(mentionEntitie.getText());
            }
            saveConnection(date, name, document2, 3, count, ConnectionCollection);
            count++;
        }
        document.append("Mentions", allmentionedUsers);

        if (exist) {
            allTweets = (ArrayList) theObj.get("Tweets");
        }
        String tweetText = " ";
        if (savedTweet.isRetweet()) {
            tweetText = savedTweet.getRetweetedStatus().getText();
        } else {
            tweetText = savedTweet.getText();
        }
        BasicDBObject document2 = new BasicDBObject("Tweet", tweetText);
        if (!allTweets.contains(tweetText)) {
            allTweets.add(tweetText);
        }
        saveConnection(date, name, document2, 4, count, ConnectionCollection);
        count++;
        document.append("Tweets", allTweets);

        if (exist) {
            savedCollection.remove(searchDocument);
        }
        savedCollection.insert(document);

    }

    JaccardSimilarity js = new JaccardSimilarity();
    List<Map<List<String>, List<Float>>> list = new ArrayList<>();//This is the final list you need
    Map<List<String>, List<Float>> map1 = new HashMap<>();//This is one instance of the   map you want to store in the above map
    List<String> usersNames = new ArrayList<>();
    List<Float> usersResults = new ArrayList<>();

    BasicDBObject doc1;
    BasicDBObject doc2;
    DBCursor cursor1;
    DBCursor cursor2;
    DBObject obj1;
    DBObject obj2;
    List<String> tl1 = new ArrayList();
    List<String> tl2 = new ArrayList();

    float countSimilarity = 0;

    for (int i = 0; i < allUsers.size(); i++) {
        for (int j = i + 1; j < allUsers.size(); j++) {
            //System.out.println(i+" "+j);
            System.out.print(allUsers.get(i) + " " + allUsers.get(j) + " ");
            usersNames.add(allUsers.get(i));
            usersNames.add(allUsers.get(j));
            doc1 = new BasicDBObject("User", allUsers.get(i));
            doc2 = new BasicDBObject("User", allUsers.get(j));
            cursor1 = savedCollection.find(doc1);
            cursor2 = savedCollection.find(doc2);
            if (cursor1.hasNext() && cursor2.hasNext()) {
                obj1 = cursor1.next();
                obj2 = cursor2.next();
                tl1 = (ArrayList) obj1.get("Hashtags");
                tl2 = (ArrayList) obj2.get("Hashtags");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("Mentions");
                tl2 = (ArrayList) obj2.get("Mentions");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("Tweets");
                tl2 = (ArrayList) obj2.get("Tweets");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                tl1 = (ArrayList) obj1.get("sortUrls");
                tl2 = (ArrayList) obj2.get("sortUrls");
                countSimilarity = countSimilarity + js.findSimilarity(tl1, tl2);
                usersResults.add(js.findSimilarity(tl1, tl2));
                System.out.print(js.findSimilarity(tl1, tl2) + " ");
                usersResults.add((float) (countSimilarity / 4));
                System.out.print((float) (countSimilarity / 4) + " ");
                System.out.println();
                countSimilarity = 0;

            }

        }
        map1.put(usersNames, usersResults);
    }
    list.add(map1);

    //System.out.println(savedCollection.count());

    /*
    // Read every Element Example
    DBCursor cursor2 = savedCollection.find(searchDocument);
    if (cursor2.hasNext()) {
    theObj = cursor2.next();
    //String l =  ( String) cursor2.one().get("exist").toString();
    }
            
    BasicDBList list = new BasicDBList();
    list = (BasicDBList) theObj.get("Hashtags");
    BasicDBList l2 = new BasicDBList();
    for (int i = 0; i < list.size(); i++) {
    BasicDBObject bj = (BasicDBObject) list.get(i);
    System.out.println(bj.getString("hashtag"));
    }
            
    DBCursor cursor2 = savedCollection.find();
     List<String> list = new ArrayList();
               
    while (cursor2.hasNext()) {
    BasicDBObject document2 = (BasicDBObject) cursor2.next();
      String bj = (String) document2.get("User");
    System.out.println(bj);
     for (int i = 0; i < list.size(); i++) {
           // String bj = (String) list.get(i);
            // System.out.println(bj.getString("hashtag"));
              System.out.println(bj);
        }
     */
}

From source file:TwitterStats.Facade.Twitter.java

public Map<String, Integer> getTendencias(String user, int estudio) throws TwitterException {
    ResponseList res;//from w ww  .j  a  va  2s.c o m
    List<Status> lista = new ArrayList<>();
    Map<String, Integer> tendencias = new HashMap<>();

    for (int i = 1; i <= estudio / 200; i++) {
        res = twitter.getUserTimeline(user, new Paging(i, 200));
        lista.addAll(res);
    }

    for (Status status : lista) {
        HashtagEntity[] ht = status.getHashtagEntities();
        for (int i = 0; i < ht.length; i++) {
            String hash = ht[i].getText();
            if (tendencias.containsKey(hash)) {
                tendencias.put(hash, tendencias.get(hash) + 1);
            } else {
                tendencias.put(hash, 1);
            }
        }
    }

    return sortByValue(tendencias);
}

From source file:TwitterStats.Facade.Twitter.java

public Map<String, Integer> getTendencias(String user, Date desde, Date hasta) throws TwitterException {
    Map<String, Integer> tendencias = new HashMap<>();

    SimpleDateFormat dt = new SimpleDateFormat("yyyy-MM-dd");
    Query q = new Query("from:" + user + " since:" + dt.format(desde) + " until:" + dt.format(hasta));

    q.setCount(100);//w  w w. j av  a  2s .  c  o m
    List<Status> lista = new ArrayList<>();
    List<Status> res = twitter.search(q).getTweets();

    while (res.size() > 1 && lista.size() < 3000) {
        lista.addAll(res);

        q.setMaxId(res.get(res.size() - 1).getId());
        res = twitter.search(q).getTweets();
    }

    for (Status status : lista) {
        HashtagEntity[] ht = status.getHashtagEntities();
        for (int i = 0; i < ht.length; i++) {
            String hash = ht[i].getText();
            if (tendencias.containsKey(hash)) {
                tendencias.put(hash, tendencias.get(hash) + 1);
            } else {
                tendencias.put(hash, 1);
            }
        }
    }

    return sortByValue(tendencias);
}

From source file:twitterswingclient.TwitterClient.java

private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed
    // TODO add your handling code here:
    String consKey = "Your key";
    String consSecret = "Your secret";
    String accToken = "Your key";
    String accSecret = "Your secret";
    try {//  www  .jav a2  s  .c  om

        TwitterFactory twitterFactory = new TwitterFactory();

        Twitter twitter = twitterFactory.getInstance();

        twitter.setOAuthConsumer(consKey, consSecret);

        twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret));

        StatusUpdate statusUpdate = new StatusUpdate(status.getText());

        statusUpdate.setMedia("Feeling great",
                new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream());

        Status stat = twitter.updateStatus(statusUpdate);

        textArea.append("status.toString() = " + stat.toString());
        textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName());
        textArea.append("status.getSource() = " + stat.getSource());
        textArea.append("status.getText() = " + stat.getText());
        textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors()));
        textArea.append("status.getCreatedAt() = " + stat.getCreatedAt());
        textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId());
        textArea.append("status.getGeoLocation() = " + stat.getGeoLocation());
        textArea.append("status.getId() = " + stat.getId());
        textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId());
        textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId());
        textArea.append("status.getPlace() = " + stat.getPlace());
        textArea.append("status.getRetweetCount() = " + stat.getRetweetCount());
        textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus());
        textArea.append("status.getUser() = " + stat.getUser());
        textArea.append("status.getAccessLevel() = " + stat.getAccessLevel());
        textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities()));
        textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities()));

        if (stat.getRateLimitStatus() != null) {
            textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit());
            textArea.append(
                    "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining());
            textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = "
                    + stat.getRateLimitStatus().getResetTimeInSeconds());
            textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = "
                    + stat.getRateLimitStatus().getSecondsUntilReset());
            textArea.append("status.getRateLimitStatus().getRemainingHits() = "
                    + stat.getRateLimitStatus().getRemaining());
        }
        textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities()));
        textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities()));

    } catch (IOException ex) {
        textArea.append("IO Exception");
    } catch (TwitterException tw) {
        textArea.append("Twitter Exception");
    }
}

From source file:uk.ac.susx.tag.method51.twitter.Tweet.java

License:Apache License

public Tweet(Status status) {
    this();//from   w  w  w  .  j  a  va2s  . co m
    created = status.getCreatedAt();
    id = status.getId();
    text = status.getText();

    inReplyToStatusId = status.getInReplyToStatusId();
    inReplyToUserId = status.getInReplyToUserId();

    originalText = null;
    retweetId = -1;
    isTruncated = status.isTruncated();
    isRetweet = status.isRetweet();
    Status entities = status;
    if (isRetweet) {
        Status origTweet = status.getRetweetedStatus();
        entities = origTweet;
        retweetId = origTweet.getId();
        originalText = text;
        text = origTweet.getText();
    }

    StringBuilder sb = new StringBuilder();

    for (HashtagEntity e : entities.getHashtagEntities()) {
        sb.append(e.getText());
        sb.append(" ");
    }
    hashtags = sb.toString();
    sb = new StringBuilder();

    for (UserMentionEntity e : entities.getUserMentionEntities()) {
        sb.append(e.getScreenName());
        sb.append(" ");
    }
    mentions = sb.toString();
    sb = new StringBuilder();

    for (URLEntity e : entities.getURLEntities()) {
        //String url = e.getURL();
        String url = e.getExpandedURL();
        if (url == null) {
            url = e.getURL();
            if (url != null) {
                sb.append(url);
            }

        } else {
            sb.append(url);
        }
        sb.append(" ");
    }
    urls = sb.toString();
    sb = new StringBuilder();

    //seems to be null if no entries
    MediaEntity[] mediaEntities = entities.getMediaEntities();
    if (mediaEntities != null) {
        for (MediaEntity e : mediaEntities) {
            String url = e.getMediaURL();
            sb.append(url);
            sb.append(" ");
        }
        mediaUrls = sb.toString();
    } else {
        mediaUrls = "";
    }

    received = new Date();

    source = status.getSource();
    GeoLocation geoLoc = status.getGeoLocation();
    Place place = status.getPlace();

    if (geoLoc != null) {

        geoLong = geoLoc.getLongitude();
        geoLat = geoLoc.getLatitude();
    } else if (place != null && place.getBoundingBoxCoordinates() != null
            && place.getBoundingBoxCoordinates().length > 0) {

        GeoLocation[] locs = place.getBoundingBoxCoordinates()[0];

        double avgLat = 0;
        double avgLon = 0;

        for (GeoLocation loc : locs) {

            avgLat += loc.getLatitude();
            avgLon += loc.getLongitude();
        }

        avgLat /= locs.length;
        avgLon /= locs.length;

        geoLat = avgLat;
        geoLong = avgLon;
    } else {

        geoLong = null;
        geoLat = null;
    }

    twitter4j.User user = status.getUser();

    if (user != null) {
        userId = user.getId();
        location = user.getLocation();
        screenName = user.getScreenName();
        following = user.getFriendsCount();
        name = user.getName();
        lang = user.getLang();
        timezone = user.getTimeZone();
        userCreated = user.getCreatedAt();
        followers = user.getFollowersCount();
        statusCount = user.getStatusesCount();
        description = user.getDescription();
        url = user.getURL();
        utcOffset = user.getUtcOffset();
        favouritesCount = user.getFavouritesCount();

        this.user = new User(user);
    }
}