Example usage for twitter4j Status getSource

List of usage examples for twitter4j Status getSource

Introduction

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

Prototype

String getSource();

Source Link

Document

Returns the source

Usage

From source file:org.tweetalib.android.model.TwitterStatus.java

License:Apache License

public TwitterStatus(Status status) {
    User statusUser = status.getUser();/*from www .ja v a 2s  .  c o m*/

    mCreatedAt = status.getCreatedAt();
    mId = status.getId();
    if (status.getInReplyToStatusId() != -1) {
        mInReplyToStatusId = status.getInReplyToStatusId();
    }
    if (status.getInReplyToUserId() != -1) {
        mInReplyToUserId = status.getInReplyToUserId();
    }
    mInReplyToUserScreenName = status.getInReplyToScreenName();
    mIsFavorited = status.isFavorited();
    mIsRetweet = status.isRetweet();
    mIsRetweetedByMe = status.isRetweetedByMe();

    mSource = TwitterUtil.stripMarkup(status.getSource());

    if (statusUser != null) {
        mUserId = statusUser.getId();
        mUserName = statusUser.getName();
        mUserScreenName = statusUser.getScreenName();
    }

    mMediaEntity = TwitterMediaEntity.createMediaEntity(status);

    boolean useDefaultAuthor = true;
    if (mIsRetweet) {
        if (status.getRetweetedStatus() != null && status.getRetweetedStatus().getUser() != null) {
            SetProfileImagesFromUser(new TwitterUser(status.getRetweetedStatus().getUser()));
        }
        mOriginalRetweetId = status.getRetweetedStatus().getId();

        // You'd think this check wasn't necessary, but apparently not...
        UserMentionEntity[] userMentions = status.getUserMentionEntities();
        if (userMentions != null && userMentions.length > 0) {
            useDefaultAuthor = false;
            UserMentionEntity authorMentionEntity = status.getUserMentionEntities()[0];
            mAuthorId = authorMentionEntity.getId();
            mAuthorName = authorMentionEntity.getName();
            mAuthorScreenName = authorMentionEntity.getScreenName();

            Status retweetedStatus = status.getRetweetedStatus();
            mStatus = retweetedStatus.getText();
            setStatusMarkup(retweetedStatus);
            mRetweetCount = retweetedStatus.getRetweetCount();
            mUserMentions = TwitterUtil.getUserMentions(retweetedStatus.getUserMentionEntities());
            mIsRetweetedByMe = retweetedStatus.isRetweetedByMe();
        }
    } else {
        if (statusUser != null) {
            SetProfileImagesFromUser(new TwitterUser(statusUser));
        }
    }

    if (useDefaultAuthor) {
        if (statusUser != null) {
            mAuthorId = statusUser.getId();
        }
        mStatus = status.getText();
        setStatusMarkup(status);
        mRetweetCount = status.getRetweetCount();
        mUserMentions = TwitterUtil.getUserMentions(status.getUserMentionEntities());
    }

    /*
     * if (status.getId() == 171546910249852928L) { mStatus =
     * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?"
     * ; mStatusMarkup =
     * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?"
     * ; mAuthorScreenName = "emmarclarke"; mStatusMarkup = mStatus; } else
     * if (status.getId() == 171444098698457089L) { mStatus =
     * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?"
     * ; mStatusMarkup =
     * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?"
     * ; mStatusMarkup = mStatus; }
     */
}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(Status t) throws XMLStreamException {
    startElement("tweet");
    attribute("id", t.getId());

    // write("annotations",t.getAnnotations());
    write("created-at", t.getCreatedAt());
    write("from-user", sanitizeID(t.getUser().getId()), sanitizeUser(t.getUser().getName()));
    write("geo-location", t.getGeoLocation());
    write("hash-tags", t.getHashtagEntities());
    write("iso-language-code", t.getUser().getLang());
    write("location", t.getUser().getLocation());
    write("media", t.getMediaEntities());
    write("place", t.getPlace());
    write("profile-image-url", sanitizeUser(t.getUser().getProfileImageURL()));
    write("source", t.getSource());
    write("text", t.getText());
    write("to-user", sanitizeID(t.getInReplyToUserId()), sanitizeUser(t.getInReplyToScreenName()));
    write("url-entities", t.getURLEntities());
    write("user-mention-entities", t.getUserMentionEntities());

    endElement();/*  w  w  w  . j  av  a 2  s  . c  o  m*/

}

From source file:org.xmlsh.twitter.util.TwitterWriter.java

License:BSD License

public void write(String localName, Status status) throws XMLStreamException {
    if (status != null) {
        startElement(localName);//w ww  .  j  ava2 s. c  om
        attribute("id", status.getId());

        // write("annotations",t.getAnnotations());
        write("created-at", status.getCreatedAt());

        write("user", status.getUser());
        write("geo-location", status.getGeoLocation());
        write("hash-tags", status.getHashtagEntities());

        write("media", status.getMediaEntities());
        write("place", status.getPlace());

        write("source", status.getSource());
        write("text", status.getText());

        write("url-entities", status.getURLEntities());
        write("user-mention-entities", status.getUserMentionEntities());

        endElement();
    }
}

From source file:public_streaming.SampleStream.java

License:Apache License

public void onStatus(Status status) {
    System.out.println("tweet:" + status.getText());//
    System.out.println(status.getFavoriteCount());
    System.out.println("User" + status.getUser().getName() + "@" + status.getUser().getScreenName());//??,?(@xx)
    System.out.println("Posted Time:" + status.getCreatedAt());//
    System.out.println("Application Name:" + status.getSource());//
    System.out.println("Time Zone:" + status.getUser().getTimeZone());//
    System.out.println("Created Date:" + status.getUser().getCreatedAt());//?
    System.out.println("GeoLocation:" + status.getUser().getLocation());//?
    System.out.println("postID:" + status.getId());//ID
    System.out.println("UserID" + status.getUser().getId());//ID
    System.out.println("Language:" + status.getUser().getLang());//
    System.out.println("Follow:" + status.getUser().getFriendsCount());//
    System.out.println("Follower:" + status.getUser().getFollowersCount());//
}

From source file:testtweet.TweetUsingTwitter4jExample.java

/**
 * @param args the command line arguments
 *///from   w w w.  j a v a 2  s.  c  om
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  w w . j a  v  a  2 s .c om*/
            "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:twitterrest.UserSearch.java

License:Apache License

public static void main(String[] args) throws TwitterException {
    //?/*from   w  w  w  . j a  va  2 s .co m*/
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter twitter = new TwitterFactory(configuration).getInstance();
    Query query = new Query();

    // masason?Tweet
    //query.setQuery("from:anondroid3 OR to:anondroid3");
    query.setQuery("from:anondroid3");

    // ???
    QueryResult result = twitter.search(query);
    //
    System.out.println(":" + result.getTweets().size());
    // 1????Tweet?100?
    query.setCount(100);

    for (Status tweet : result.getTweets()) {
        System.out.println("tweet:" + tweet.getText());//
        System.out.println("UserID:" + tweet.getUser().getId());//ID
        System.out.println("Application:" + tweet.getSource());//
        System.out.println("Created Date:" + tweet.getCreatedAt());//?
        System.out.println("GeoLocation:" + tweet.getGeoLocation());//
    }
}

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 {//from  w  w  w  .  j a va  2 s.com

        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();//w  ww. j av a  2 s  .com
    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);
    }
}

From source file:wap.twitter.model.TwitterUtility.java

public List<Tweet> getTweets(String news) {
    TwitterFactory tf = config();//from   ww  w  .ja  va2  s. c om
    Twitter twitter = tf.getInstance();
    try {
        List<Tweet> tws = new ArrayList<Tweet>();
        int i = 0;
        Query query = new Query("#" + news);
        QueryResult result;
        do {
            result = twitter.search(query);
            List<Status> tweets = result.getTweets();
            for (Status tweet : tweets) {
                Tweet tw = new Tweet();
                if (i == 8) {
                    break;
                } else {
                    tw.setTitle(news);
                    tw.setUser(tweet.getUser().getScreenName());
                    tw.setUrl(tweet.getSource());
                    tw.setImage(tweet.getUser().getProfileImageURL());
                    tw.setBody(tweet.getText());
                    tw.setSource(tweet.getSource());
                    tw.setId(tweet.getId() + "");
                    i++;
                }
                System.out.println("******************* " + tweet.getGeoLocation());
                tws.add(tw);
            }
        } while ((query = result.nextQuery()) != null);
        return tws;
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to search tweets: " + te.getMessage());
        System.exit(-1);
    }
    return null;
}