Package twitter4j

Examples of twitter4j.Twitter$Device


        }

        @Override
        public void execute() {
            try {
                final Twitter twitter = new TwitterFactory().getInstance();
                twitter.setOAuthConsumer(consumerKey,consumerSecret);

                if(!context.getSettings().containsKey(TWITTER_TOKEN) || force) {
                    //u.p("no auth info already");
                    final RequestToken requestToken = twitter.getOAuthRequestToken();
                    final String url = requestToken.getAuthorizationURL();

                    final Textbox pin = new Textbox("");
                    pin.setPrefWidth(50);
                    pin.setWidth(50);
                    final Stage stage = Stage.createStage();
                    stage.setContent(
                            new GridBox()
                                    .createColumn(50,GridBox.Align.Right)
                                    .createColumn(50,GridBox.Align.Fill)
                                    .addControl(new Label(getString("twitterAuthDialog.text1")))
                                    .addControl(new Label(getString("twitterAuthDialog.text2")))
                                    .nextRow()
                                    .addControl(new Spacer())
                                    .addControl(new Button("Goto Twitter.com").onClicked(new Callback<ActionEvent>() {
                                        public void call(ActionEvent event) {
                                            OSUtil.openBrowser(url);
                                        }
                                    }))
                                    .nextRow()
                                    .addControl(new Label("PIN"))
                                    .addControl(pin)
                                    .nextRow()
                                    .addControl(new Button(getString("dialog.cancel")).onClicked(new Callback<ActionEvent>(){
                                        public void call(ActionEvent event) {
                                            stage.hide();
                                        }
                                    }))
                                    .addControl(new Button(getString("twitterAuthDialog.authenticate")).onClicked(new Callback<ActionEvent>(){
                                        public void call(ActionEvent event) {
                                            stage.hide();
                                            try {
                                                String pinText = pin.getText();
                                                //u.p("using pin text " + pinText);
                                                AccessToken accessToken = twitter.getOAuthAccessToken(requestToken,pinText);
                                                context.getSettings().setProperty(TWITTER_TOKEN,accessToken.getToken());
                                                context.getSettings().setProperty(TWITTER_TOKEN_SECRET,accessToken.getTokenSecret());
                                            } catch (TwitterException e) {
                                                e.printStackTrace();
                                                StandardDialog.showError("Twitter authentication failed.\nPlease try again.");
View Full Code Here


     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException, TwitterException {
        response.setContentType("text/xml;charset=UTF-8");
        PrintWriter out = response.getWriter();       
        Twitter twitter = new TwitterFactory().getInstance();
        List<User> followers = getFollowersUsers(twitter, "latinoware");
        String template = "<entry>"
                + "<title>%s</title>"
                + "<link rel=\"alternate\" type=\"text/html\" href=\"%s\" />"
                + "<id>%s</id>"
View Full Code Here

*/
public class TwitterTest {

    public static void main(String... args) throws TwitterException{
        // The factory instance is re-useable and thread safe.
        Twitter twitter = new TwitterFactory().getInstance();
        Query query = new Query("#latino");
        query.setRpp(100);
        QueryResult result = twitter.search(query);
        System.out.println("hits:" + result.getResultsPerPage());
        System.out.println(result.getMaxId() + " :" + result.getPage());
        for (Tweet tweet : result.getTweets()) {           
            User user = twitter.showUser(tweet.getFromUser());
            System.out.println(user.getLocation());
            if (user.isGeoEnabled()) {
                GeoLocation geo = user.getStatus() != null ? user.getStatus().getGeoLocation() : null;
                System.out.println(geo + ":" + tweet.getLocation() + ":" + tweet.getFromUser() + ":" + tweet.getText());
            }
View Full Code Here

          
           try {       
             TwitterVO twitterVO = configService.getTwitterCredentials();
             List<String> list = new ArrayList<String>();
            
              Twitter twitter = new Twitter(twitterVO.getTwitteruser(),twitterVO.getTwitterpswd());
             List<Status> statuses = twitter.getFriendsTimeline();
             // System.out.println("Showing friends timeline.");
             for (Status status : statuses) {
                 //System.out.println(status.getUser().getName() + ":" + status.getText());
                 list.add("<img src=\"" + status.getUser().getProfileImageURL() + "\" height=\"48\" width=\"48\" align=\"left\"><strong>" + status.getUser().getName() + "</strong>:" + status.getText());
             }            
View Full Code Here

    }

    @Override
    public InteractionState<TwitterAccessTokenContext> processOAuthInteraction(HttpServletRequest request, HttpServletResponse response) throws
            IOException, OAuthException {
        Twitter twitter = twitterFactory.getInstance();

        HttpSession session = request.getSession();

        //See if we are a callback
        RequestToken requestToken = (RequestToken) session.getAttribute(OAuthConstants.ATTRIBUTE_TWITTER_REQUEST_TOKEN);

        try {
            if (requestToken == null) {
                requestToken = twitter.getOAuthRequestToken(redirectURL);

                // Save requestToken to session, but only temporarily until oauth workflow is finished
                session.setAttribute(OAuthConstants.ATTRIBUTE_TWITTER_REQUEST_TOKEN, requestToken);

                if (log.isTraceEnabled()) {
                    log.trace("RequestToken obtained from twitter. Redirecting to Twitter for authorization");
                }

                // Redirect to twitter to perform authentication
                response.sendRedirect(requestToken.getAuthenticationURL());

                return new InteractionState<TwitterAccessTokenContext>(InteractionState.State.AUTH, null);
            } else {
                String verifier = request.getParameter(OAuthConstants.OAUTH_VERIFIER);

                // User denied scope
                if (request.getParameter(OAuthConstants.OAUTH_DENIED) != null) {
                    throw new OAuthException(OAuthExceptionCode.USER_DENIED_SCOPE, "User denied scope on Twitter authorization page");
                }

                // Obtain accessToken from twitter
                AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);

                if (log.isTraceEnabled()) {
                    log.trace("Twitter accessToken: " + accessToken);
                }
View Full Code Here

    @Override
    public TwitterAccessTokenContext validateTokenAndUpdateScopes(TwitterAccessTokenContext accessToken) throws OAuthException {
        try {
            // Perform validation by obtaining some info about user
            Twitter twitter = getAuthorizedTwitterInstance(accessToken);
            twitter.verifyCredentials();
            return accessToken;
        } catch (TwitterException tw) {
            if (tw.getStatusCode() == 401) {
                throw new OAuthException(OAuthExceptionCode.ACCESS_TOKEN_ERROR,
                        "Error when verifying twitter access token: " + tw.getMessage(), tw);
View Full Code Here

  @SuppressWarnings({ "unchecked", "deprecation" })
  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws IOException {
    Date d = new Date();
    if (d.getHours() >= 10) {
      Twitter tw = new Twitter("Yarikx", "saxophon");
      try {
        List<Status> l = tw.getFriendsTimeline();

        PrintWriter pw = response.getWriter();

        for (Status status : l) {
          TwStatus ts = new TwStatus(status);
View Full Code Here

            log.debug("loading accessToken from " + accessTokenFilePath);
            log.debug("token: [" + accessToken.getToken() + "]");
            log.debug("tokenSecret: [" + accessToken.getTokenSecret() + "]");

            Twitter twitter = tFactory.getInstance();
            twitter.setOAuthConsumer(consumerKey, consumerSecret);
            twitter.setOAuthAccessToken(accessToken);

            AlertManagerLocal alertManager = LookupUtil.getAlertManager();
            StringBuilder b = new StringBuilder("Alert ");
            b.append(alert.getId()).append(":'"); // Alert id
            b.append(alert.getAlertDefinition().getResource().getName());
            b.append("' (");
            b.append(alert.getAlertDefinition().getResource().getId());
            b.append("): ");
            b.append(alertManager.prettyPrintAlertConditions(alert, true));
            b.append("-by " + this.alertParameters.getSimpleValue("twittedBy", "@RHQ")); // TODO not for production :-)
            // TODO use some alert url shortening service

            String msg = b.toString();
            if (msg.length() > 140)
                msg = msg.substring(0, 140);

            Status status = twitter.updateStatus(msg);

            result = SenderResult.getSimpleSuccess("Send notification - msg-id: " + status.getId());
        } catch (TwitterException e) {

            log.warn("Notification via Microblog failed!", e);
View Full Code Here

     */
    public  void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {

       for (MeasurementScheduleRequest req : metrics) {
          if (req.getName().equals("tweetCount")) {
             Twitter twitter = tFactory.getInstance();
             Paging paging = new Paging();

             MeasurementDataNumeric res;
             if (isSearch) {
                Query q = new Query(keyword);
                q.setSinceId(lastId);
                if (lastId == NOT_YET_SET)
                  q.setRpp(1);
                else
                  q.setRpp(20);
                QueryResult qr = twitter.search(q);
                List<Tweet> tweets = qr.getTweets();
                res = new MeasurementDataNumeric(req, (double) tweets.size());

                eventPoller.addTweets(tweets);
                if (tweets.size()>0)
                   lastId = tweets.get(0).getId();
             }
             else {
                List<Status> statuses;
                if (lastId == NOT_YET_SET) {
                   paging.setCount(1);
                }
                else {
                   paging.setCount(100);
                }
                paging.setSinceId(lastId);
                statuses = twitter.getUserTimeline(keyword,paging);
                res = new MeasurementDataNumeric(req, (double) statuses.size());

                eventPoller.addStatuses(statuses);
                if (statuses.size()>0)
                   lastId = statuses.get(0).getId();
View Full Code Here

     * Gather measurement data
     *  @see org.rhq.core.pluginapi.measurement.MeasurementFacet#getValues(org.rhq.core.domain.measurement.MeasurementReport, java.util.Set)
     */
    public  void getValues(MeasurementReport report, Set<MeasurementScheduleRequest> metrics) throws Exception {

       Twitter twitter = createTwitterInstance();

       for (MeasurementScheduleRequest req : metrics) {
          if (req.getName().equals("tweetCount")) {

//             Twitter twitter = new Twitter(username,password,serverUrl);
             Paging paging = new Paging();
             if (lastId == NOT_YET_SET) {
                paging.setSinceId(1);
                paging.setCount(1);
             }
             else {
                paging.setSinceId(lastId);
                paging.setCount(100);
             }
             List<Status> statuses;
             statuses = twitter.getHomeTimeline(paging);
             if (lastId>0) {
                MeasurementDataNumeric res;
                res = new MeasurementDataNumeric(req, (double) statuses.size());

                eventPoller.addStatuses(statuses);
                report.addData(res);
             }
             if (statuses.size()>0)
                lastId = statuses.get(0).getId(); // This is always newest first
          }
          else if (req.getName().equals("followerCount")) {
              int count = twitter.getFollowersIDs(-1).getIDs().length;
              MeasurementDataNumeric res;
              res = new MeasurementDataNumeric(req,(double)count);
              report.addData(res);
          }
       }
View Full Code Here

TOP

Related Classes of twitter4j.Twitter$Device

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.