Example usage for twitter4j TwitterException getMessage

List of usage examples for twitter4j TwitterException getMessage

Introduction

In this page you can find the example usage for twitter4j TwitterException getMessage.

Prototype

@Override
    public String getMessage() 

Source Link

Usage

From source file:com.itbs.aimcer.commune.twitter.TwitterConnection.java

License:Open Source License

/**
 * Overide this message with code that sends the message out.
 *
 * @param message to send/*ww w .ja v a 2s  .  c  o  m*/
 * @throws java.io.IOException problems
 */
protected void processMessage(Message message) throws IOException {
    try {
        connection.sendDirectMessage(message.getContact().getName(), message.getPlainText());
    } catch (TwitterException e) {
        log.log(Level.SEVERE, "", e);
        throw new IOException(e.getMessage());
    }
}

From source file:com.javielinux.api.loaders.CheckConversationLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*from   w  ww.j  av  a  2s . c om*/
        CheckConversationResponse response = new CheckConversationResponse();
        ConnectionManager.getInstance().open(getContext());
        if (request.getFrom() == InfoTweet.FROM_STATUS) {
            response.setStatus(ConnectionManager.getInstance().getTwitter(request.getUserId())
                    .showStatus(request.getConversation()));
        } else {
            long i = ConnectionManager.getInstance().getTwitter(request.getUserId())
                    .showStatus(request.getConversation()).getInReplyToStatusId();
            if (i > 0) {
                response.setStatus(
                        ConnectionManager.getInstance().getTwitter(request.getUserId()).showStatus(i));
            }
        }
        return response;
    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse error = new ErrorResponse();
        error.setError(e, e.getMessage());
        return error;
    }

}

From source file:com.javielinux.api.loaders.ConversationLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*  ww  w.  j av  a2  s .  co m*/
        ConversationResponse response = new ConversationResponse();

        ConnectionManager.getInstance().open(getContext());
        ArrayList<Status> tweets = new ArrayList<twitter4j.Status>();
        twitter4j.Status st = ConnectionManager.getInstance().getTwitter(request.getUserId())
                .showStatus(request.getId());

        tweets.add(st);
        while (st.getInReplyToStatusId() > 0) {
            st = ConnectionManager.getInstance().getTwitter(request.getUserId())
                    .showStatus(st.getInReplyToStatusId());
            tweets.add(st);
        }
        response.setTweets(tweets);
        return response;
    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse error = new ErrorResponse();
        error.setError(e, e.getMessage());
        return error;
    }

}

From source file:com.javielinux.api.loaders.CreateUserListsLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {
    try {/*from   www.ja v  a 2  s. co m*/
        ConnectionManager.getInstance().open(getContext());
        ConnectionManager.getInstance().getTwitter(request.getUserId()).createUserList(request.getTitle(),
                request.isPublic(), request.getDescription());
        return new CreateUserListsResponse();
    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse response = new ErrorResponse();
        response.setError(e, e.getMessage());
        return response;
    }
}

From source file:com.javielinux.api.loaders.DirectMessageLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*  w  w w.ja v a 2s. co  m*/
        DirectMessageResponse response = new DirectMessageResponse();
        if (request.getModeTweetLonger() == NewStatusActivity.MODE_TL_NONE) {
            ConnectionManager.getInstance().getTwitter(request.getUserId()).sendDirectMessage(request.getUser(),
                    request.getText());
        } else {
            ArrayList<String> ar = Utils.getDivide140(request.getText(), "");
            for (String t : ar) {
                ConnectionManager.getInstance().getTwitter(request.getUserId())
                        .sendDirectMessage(request.getUser(), t);
            }
        }
        response.setSent(true);
        return response;
    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse error = new ErrorResponse();
        error.setError(e, e.getMessage());
        return error;
    } catch (Exception e) {
        e.printStackTrace();
        ErrorResponse error = new ErrorResponse();
        error.setError(e, e.getMessage());
        return error;
    }

}

From source file:com.javielinux.api.loaders.GetConversationLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {// ww w  .ja va  2 s.  co m

        GetConversationResponse response = new GetConversationResponse();

        ConnectionManager.getInstance().open(getContext());
        twitter4j.Status status = ConnectionManager.getInstance().getUserForSearchesTwitter()
                .showStatus(request.getId());

        InfoTweet infoTweet = new InfoTweet(status);
        response.setConversationTweet(infoTweet);

        // TODO : ver como funciona el publish progress en los loaders
        /*
        publishProgress(result);
                
        while (status.getInReplyToStatusId() > 0) {
        status = ConnectionManager.getInstance().getTwitter().showStatus(status.getInReplyToStatusId());
                
        result.conversation_status = status;
        publishProgress(result);
        }             */

        return response;
    } catch (TwitterException exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    }

}

From source file:com.javielinux.api.loaders.GetUserFriendshipMembersLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*from  w  ww  .  j  a  va 2  s . co  m*/
        GetUserFriendshipMembersResponse response = new GetUserFriendshipMembersResponse();
        ArrayList<InfoTweet> result = new ArrayList<InfoTweet>();

        ConnectionManager.getInstance().open(getContext());

        if (request.getType() == FOLLOWERS) {
            long cursor = -1;
            IDs followers_ids_response = ConnectionManager.getInstance().getUserForSearchesTwitter()
                    .getFollowersIDs(request.getUser(), cursor);

            response.setFriendshipMembersIds(followers_ids_response.getIDs());
        } else if (request.getType() == FRIENDS) {
            long cursor = -1;
            IDs friends_ids_response = ConnectionManager.getInstance().getUserForSearchesTwitter()
                    .getFriendsIDs(request.getUser(), cursor);

            response.setFriendshipMembersIds(friends_ids_response.getIDs());
        }

        return response;

    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse response = new ErrorResponse();
        response.setError(e, e.getMessage());
        return response;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        ErrorResponse response = new ErrorResponse();
        response.setError(e, e.getMessage());
        return response;
    } catch (Exception e) {
        e.printStackTrace();
        ErrorResponse response = new ErrorResponse();
        response.setError(e, e.getMessage());
        return response;
    }
}

From source file:com.javielinux.api.loaders.ImageUploadLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {// w w w. ja  v a2s. c o m

        ImageUploadResponse response = new ImageUploadResponse();

        String f = Utils.appUploadImageDirectory + request.getFilename();

        response.setFile(request.getFilename());
        /*
           int size = Integer.parseInt(Utils.getPreference(mContext).getString("prf_size_photo", "2"));
                
           if (size == 1) {
           Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_SMALL);
           if (resizedBitmap!=null) {
               FileOutputStream out = new FileOutputStream(f);
               resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out);
           }
           } else if (size == 2) {
           Bitmap resizedBitmap = Utils.getResizeBitmapFromFile(f, Utils.HEIGHT_PHOTO_SIZE_MIDDLE);
           if (resizedBitmap!=null) {
               FileOutputStream out = new FileOutputStream(f);
               resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 95, out);
           }
           }
           */
        response.setBmp(ImageUtils.getBitmapFromFile(f, Utils.HEIGHT_THUMB_NEWSTATUS, true));

        File file = new File(f);

        int type = Integer.parseInt(Utils.getPreference(getContext()).getString("prf_service_image", "1"));

        MediaProvider mp = MediaProvider.YFROG;

        if (type == 1) {
            mp = MediaProvider.YFROG;
        } else if (type == 2) {
            mp = MediaProvider.TWITPIC;
        } else if (type == 3) {
            mp = MediaProvider.PLIXI;
        }

        loadConsumerKeys();

        ConfigurationBuilder confBuild = new ConfigurationBuilder();
        confBuild.setOAuthConsumerKey(consumerKey);
        confBuild.setOAuthConsumerSecret(consumerSecretKey);
        confBuild.setOAuthAccessToken(ConnectionManager.getInstance().getTwitter(request.getUserId())
                .getOAuthAccessToken().getToken());
        confBuild.setOAuthAccessTokenSecret(ConnectionManager.getInstance().getTwitter(request.getUserId())
                .getOAuthAccessToken().getTokenSecret());
        if (type == 1) {
        } else if (type == 2) {
            confBuild.setMediaProviderAPIKey("e3533af853e8f63a0018a2c63d7ee69f");
        } else if (type == 3) {
            confBuild.setMediaProviderAPIKey("57438faa-51e4-43a5-9e15-0c63b6f73950");
        }

        confBuild.setMediaProvider(mp.name());
        Configuration config = confBuild.build();

        ImageUpload upload = new ImageUploadFactory(config).getInstance(mp);
        if (upload != null) {
            response.setUrl(upload.upload(file));
            return response;
        } else {
            ErrorResponse errorResponse = new ErrorResponse();
            errorResponse.setError("Image upload is null");
            return errorResponse;
        }

    } catch (TwitterException exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    } catch (Exception exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    }

}

From source file:com.javielinux.api.loaders.ListUserTwitterLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*w  ww  . ja  va  2 s .  c  om*/

        ListUserTwitterResponse response = new ListUserTwitterResponse();

        ArrayList<InfoUsers> ar = new ArrayList<InfoUsers>();
        ResponseList<User> users = ConnectionManager.getInstance().getTwitter(request.getUserId())
                .searchUsers(request.getUser(), 0);
        for (int i = 0; i < users.size(); i++) {
            ar.add(new InfoUsers(users.get(i)));
        }
        response.setUsers(ar);
        return response;
    } catch (TwitterException e) {
        e.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            errorResponse.setTypeError(Utils.LIMIT_ERROR);
            errorResponse.setRateError(rate);
        } else {
            errorResponse.setTypeError(Utils.UNKNOWN_ERROR);
        }
        errorResponse.setError(e, e.getMessage());
        return errorResponse;
    }

}

From source file:com.javielinux.api.loaders.LoadMoreTweetDownLoader.java

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {//from   w  w w  . ja v  a2s.co  m

        LoadMoreTweetDownResponse response = new LoadMoreTweetDownResponse();

        PreferenceManager.setDefaultValues(getContext(), R.xml.preferences, false);
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getContext());
        int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60"));
        if (maxDownloadTweet <= 0)
            maxDownloadTweet = 60;

        ConnectionManager.getInstance().open(getContext());

        Twitter twitter = ConnectionManager.getInstance().getTwitter(request.getUserId());

        Paging p = new Paging();
        p.setCount(maxDownloadTweet);
        p.setSinceId(request.getSinceId());
        p.setMaxId(request.getMaxId());

        ResponseList<Status> statii = null;

        try {
            statii = twitter.getHomeTimeline(p);
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
        }

        boolean breakTimeline = false;

        if (statii != null && statii.size() >= maxDownloadTweet - 10) {
            p = new Paging(1, 10);
            p.setSinceId(request.getSinceId());
            p.setMaxId(statii.get(statii.size() - 1).getId());
            if (twitter.getHomeTimeline().size() > 0) {
                breakTimeline = true;
                response.setHasMoreTweets(true);
            }
        }

        if (statii != null) {

            if (statii.size() > 0) {

                try {
                    DataFramework.getInstance().open(getContext(), Utils.packageName);
                } catch (Exception e) {
                    e.printStackTrace();
                }

                List<InfoTweet> tweets = new ArrayList<InfoTweet>();
                for (Status status : statii) {
                    tweets.add(new InfoTweet(status));
                }
                response.setTweets(tweets);

                long nextId = 1;
                Cursor c = DataFramework.getInstance().getCursor("tweets_user",
                        new String[] { DataFramework.KEY_ID }, null, null, null, null,
                        DataFramework.KEY_ID + " desc", "1");
                if (!c.moveToFirst()) {
                    c.close();
                    nextId = 1;
                } else {
                    long Id = c.getInt(0) + 1;
                    c.close();
                    nextId = Id;
                }

                try {
                    boolean isFirst = true;
                    for (int i = statii.size() - 1; i >= 0; i--) {
                        User u = statii.get(i).getUser();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", TweetTopicsUtils.TWEET_TYPE_TIMELINE);
                            args.put("user_tt_id", "" + request.getUserId());
                            if (u.getProfileImageURL() != null) {
                                args.put("url_avatar", u.getProfileImageURL().toString());
                            } else {
                                args.put("url_avatar", "");
                            }
                            args.put("username", u.getScreenName());
                            args.put("fullname", u.getName());
                            args.put("user_id", "" + u.getId());
                            args.put("tweet_id", Utils.fillZeros("" + statii.get(i).getId()));
                            args.put("source", statii.get(i).getSource());
                            args.put("to_username", statii.get(i).getInReplyToScreenName());
                            args.put("to_user_id", "" + statii.get(i).getInReplyToUserId());
                            args.put("date", String.valueOf(statii.get(i).getCreatedAt().getTime()));
                            if (statii.get(i).getRetweetedStatus() != null) {
                                args.put("is_retweet", 1);
                                args.put("retweet_url_avatar", statii.get(i).getRetweetedStatus().getUser()
                                        .getProfileImageURL().toString());
                                args.put("retweet_username",
                                        statii.get(i).getRetweetedStatus().getUser().getScreenName());
                                args.put("retweet_source", statii.get(i).getRetweetedStatus().getSource());
                                String t = Utils.getTwitLoger(statii.get(i).getRetweetedStatus());
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getRetweetedStatus().getText());
                                    args.put("text_urls",
                                            Utils.getTextURLs(statii.get(i).getRetweetedStatus()));
                                } else {
                                    args.put("text", t);
                                }
                                args.put("is_favorite", 0);
                            } else {
                                String t = Utils.getTwitLoger(statii.get(i));
                                if (t.equals("")) {
                                    args.put("text", statii.get(i).getText());
                                    args.put("text_urls", Utils.getTextURLs(statii.get(i)));
                                } else {
                                    args.put("text", t);
                                }

                                if (statii.get(i).isFavorited()) {
                                    args.put("is_favorite", 1);
                                }
                            }

                            if (statii.get(i).getGeoLocation() != null) {
                                args.put("latitude", statii.get(i).getGeoLocation().getLatitude());
                                args.put("longitude", statii.get(i).getGeoLocation().getLongitude());
                            }
                            args.put("reply_tweet_id", statii.get(i).getInReplyToStatusId());

                            if (breakTimeline && isFirst)
                                args.put("has_more_tweets_down", 1);

                            DataFramework.getInstance().getDB().insert("tweets_user", null, args);

                            nextId++;

                            if (isFirst)
                                isFirst = false;
                        }

                    }

                } catch (SQLException e) {
                    e.printStackTrace();
                }

                DataFramework.getInstance().close();

            }

        }

        return response;

    } catch (TwitterException twitterException) {
        twitterException.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(twitterException, twitterException.getMessage());
        return errorResponse;
    } catch (Exception exception) {
        exception.printStackTrace();
        ErrorResponse errorResponse = new ErrorResponse();
        errorResponse.setError(exception, exception.getMessage());
        return errorResponse;
    }

}