Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text of the status

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 w w .j  a v a 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.esz.thaifloodreporter.UpdateStatus.java

License:Apache License

/**
 * Usage: java twitter4j.examples.tweets.UpdateStatus [text]
 *
 * @param args message//from w  ww .  ja v  a  2 s  .c om
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        try {
            // get request token.
            // this will throw IllegalStateException if access token is already available
            RequestToken requestToken = twitter.getOAuthRequestToken();
            System.out.println("Got request token.");
            System.out.println("Request token: " + requestToken.getToken());
            System.out.println("Request token secret: " + requestToken.getTokenSecret());
            AccessToken accessToken = null;

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            while (null == accessToken) {
                System.out.println("Open the following URL and grant access to your account:");
                System.out.println(requestToken.getAuthorizationURL());
                System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:");
                String pin = br.readLine();
                try {
                    if (pin.length() > 0) {
                        accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                    } else {
                        accessToken = twitter.getOAuthAccessToken(requestToken);
                    }
                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) {
                        System.out.println("Unable to get the access token.");
                    } else {
                        te.printStackTrace();
                    }
                }
            }
            System.out.println("Got access token.");
            System.out.println("Access token: " + accessToken.getToken());
            System.out.println("Access token secret: " + accessToken.getTokenSecret());
        } catch (IllegalStateException ie) {
            // access token is already available, or consumer key/secret is not set.
            if (!twitter.getAuthorization().isEnabled()) {
                System.out.println("OAuth consumer key/secret is not set.");
                System.exit(-1);
            }
        }
        Status status = twitter.updateStatus(args[0]);
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get timeline: " + te.getMessage());
        System.exit(-1);
    } catch (IOException ioe) {
        ioe.printStackTrace();
        System.out.println("Failed to read the system input.");
        System.exit(-1);
    }
}

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 {/*from   w  w w.java2 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.eventattend.portal.bl.TwitterBL.java

License:Open Source License

public boolean shareMsgInTwitter(Twitter twitter, String Msg) throws BaseAppException {

    boolean result = false;
    Status status = null;
    try {//from  w w w.  j av  a2 s.c  om
        if (Msg != null) {
            if (Msg.length() >= 140) {
                String st[] = splitTweetToLimit(Msg);
                for (int c = 0; c <= st.length; c++) {
                    if (st[c] == null) {
                        break;
                    }
                    System.out.println("Splited Tweets " + c + " >> " + st[c]);
                    status = twitter.updateStatus(st[c]);
                    result = true;
                }
            } else {
                status = twitter.updateStatus(Msg);
                result = true;
            }
        }
    } catch (TwitterException e) {
        result = false;
        System.out.println("Exception while updating the status to [" + status.getText() + "].");
        processTwitterException(e);
    }
    return result;
}

From source file:com.example.android.ActivityTweetArrayAdapter.java

License:Apache License

@Override
public View getDropDownView(int position, View view, ViewGroup parent) {
    if (view == null) {
        final LayoutInflater inflater = (LayoutInflater) getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.activity_list, parent, false);
    }//from w w w  .  j a  v  a  2s .  c o  m
    Status status = getItem(position);
    if (null == status) {
        return view;
    }
    ((TextView) view.findViewById(R.id.twitter)).setText(status.getText());

    return view;
}

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);/*w ww  . j  a v  a 2 s  .  c o m*/
        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.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)/* w  w w.  j a  va2s .com*/
            /* 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.freedomotic.plugins.devices.twitter.gateways.OAuthSetup.java

License:Open Source License

/**
 * @param args/*w  w  w  .j a va 2s .  c o  m*/
 */
public static void main(String args[]) throws Exception {
    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();

    //insert the appropriate consumer key and consumer secret here

    twitter.setOAuthConsumer("TLGtvoeABqf2tEG4itTUaw", "nUJPxYR1qJmhX9SnWTBT0MzO7dIqUtNyVPfhg10wf0");
    RequestToken requestToken = twitter.getOAuthRequestToken();
    AccessToken accessToken = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (null == accessToken) {
        System.out.println("Open the following URL and grant access to your account:");
        System.out.println(requestToken.getAuthorizationURL());
        System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
        String pin = br.readLine();
        try {
            if (pin.length() > 0) {
                accessToken = twitter.getOAuthAccessToken(requestToken, pin);
            } else {
                accessToken = twitter.getOAuthAccessToken();
            }
        } catch (TwitterException te) {
            if (401 == te.getStatusCode()) {
                System.out.println("Unable to get the access token.");
            } else {
                te.printStackTrace();
            }
        }
    }
    //persist to the accessToken for future reference.
    System.out.println(twitter.verifyCredentials().getId());
    System.out.println("token : " + accessToken.getToken());
    System.out.println("tokenSecret : " + accessToken.getTokenSecret());
    //storeAccessToken(twitter.verifyCredentials().getId() , accessToken);
    Status status = twitter.updateStatus(args[0]);
    System.out.println("Successfully updated the status to [" + status.getText() + "].");
    System.exit(0);
}

From source file:com.freedomotic.plugins.devices.twitter.TwitterActuator.java

License:Open Source License

@Override
protected void onCommand(Command c) throws IOException, UnableToExecuteException {
    if (isRunning()) {
        try {//from  ww  w.  j a v  a 2 s  .co  m
            //Maybe we can use the async api
            //First implementation. We can extend sending a mes to an specific user (for example)
            String statusmess = c.getProperty("status");
            Status status = twitter.updateStatus(statusmess);
            System.out.println("Successfully updated the status to [" + status.getText() + "].");
        } catch (TwitterException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
}