Example usage for twitter4j User getName

List of usage examples for twitter4j User getName

Introduction

In this page you can find the example usage for twitter4j User getName.

Prototype

String getName();

Source Link

Document

Returns the name of the user

Usage

From source file:com.google.appinventor.components.runtime.Twitter.java

License:Open Source License

/**
 * Gets who is following you./*from  w w  w  .j  ava2s. c  o m*/
 */
@SimpleFunction
public void RequestFollowers() {
    if (twitter == null || userName.length() == 0) {
        form.dispatchErrorOccurredEvent(this, "RequestFollowers",
                ErrorMessages.ERROR_TWITTER_REQUEST_FOLLOWERS_FAILED, "Need to login?");
        return;
    }
    AsynchUtil.runAsynchronously(new Runnable() {
        List<User> friends = new ArrayList<User>();

        public void run() {
            try {
                IDs followerIDs = twitter.getFollowersIDs(-1);
                for (long id : followerIDs.getIDs()) {
                    // convert from the IDs returned to the User
                    friends.add(twitter.showUser(id));
                }
            } catch (TwitterException e) {
                form.dispatchErrorOccurredEvent(Twitter.this, "RequestFollowers",
                        ErrorMessages.ERROR_TWITTER_REQUEST_FOLLOWERS_FAILED, e.getMessage());
            } finally {
                handler.post(new Runnable() {
                    public void run() {
                        followers.clear();
                        for (User user : friends) {
                            followers.add(user.getName());
                        }
                        FollowersReceived(followers);
                    }
                });
            }
        }
    });
}

From source file:com.industrialtsi.mylyn.twitter.persistor.TwitterPersistor.java

License:Open Source License

@Override
public List<String> getLegalOwners(TaskRepository repository) throws SQLException, CoreException {

    Twitter t = getTwitter(repository);/*  w w  w.  j a  v  a 2 s .  c  om*/

    List<String> result = new ArrayList<String>();
    List<User> friends;
    try {
        friends = t.getFriendsStatuses();
        for (User friend : friends) {
            result.add(friend.getName() + " (" + friend.getScreenName() + ")");
        }
        Object[] res = result.toArray();
        Arrays.sort(res);
        result = new ArrayList<String>();
        for (Object object : res) {
            result.add((String) object);
        }
        return result;
    } catch (TwitterException e) {
        IStatus status = CoreLogger.createStatus(IStatus.ERROR, e);
        throw new CoreException(status);
    }
}

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

License:Open Source License

private void getList() throws TwitterException {
    Group lastGroup;/*from w  w w .j a  v a 2  s. c om*/
    Contact contact;
    getGroupList().add(lastGroup = getGroupFactory().create(GROUP));
    lastGroup.clear(this); // b/c of reconnect
    IDs followersIDs = connection.getFollowersIDs(connection.getId());
    ResponseList<User> users = connection.lookupUsers(followersIDs.getIDs());
    for (User user : users) {
        contact = getContactFactory().create(user.getName(), this);
        lastGroup.add(contact);
    } // while
}

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

License:Apache License

@Override
public BaseResponse loadInBackground() {

    try {/*from ww w. j  a v  a2 s.  c o  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;
    }

}

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

License:Apache License

private boolean refreshAvatar() {

    if (request.getUserId() > 0) {
        try {//from   w ww  .  ja va 2  s . c  om
            ConnectionManager.getInstance().open(getContext());
            Entity ent = new Entity("users", request.getUserId());
            User user = ConnectionManager.getInstance().getTwitter(request.getUserId())
                    .showUser(ent.getInt("user_id"));
            Bitmap avatar = BitmapFactory.decodeStream(
                    new Utils.FlushedInputStream(new URL(user.getProfileImageURL()).openStream()));
            String file = ImageUtils.getFileAvatar(request.getUserId());

            FileOutputStream out = new FileOutputStream(file);
            avatar.compress(Bitmap.CompressFormat.JPEG, 90, out);

            ent.setValue("fullname", user.getName());
            ent.save();

            avatar.recycle();
        } catch (NullPointerException e) {
            e.printStackTrace();
            return false;
        } catch (OutOfMemoryError e) {
            e.printStackTrace();
            return false;
        } catch (TwitterException e) {
            e.printStackTrace();
            return false;
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }

    return true;
}

From source file:com.javielinux.database.EntitySearch.java

License:Apache License

public InfoSaveTweets saveTweets(Context cnt, boolean saveNotifications, long since_id) {
    ConnectionManager.getInstance().open(cnt);
    Twitter twitter = ConnectionManager.getInstance().getUserForSearchesTwitter();
    InfoSaveTweets out = new InfoSaveTweets();
    try {//from  w ww .j  a v a2s.  c  o  m
        int nResult = DataFramework.getInstance().getEntityListCount("tweets",
                "favorite=0 and search_id=" + getId());

        Query query = getQuery(cnt);
        if (since_id != -1)
            query.setSinceId(since_id);

        QueryResult result = twitter.search(query);
        ArrayList<Status> tweets = (ArrayList<Status>) result.getTweets();

        if (tweets.size() > 0) {

            out.setNewMessages(tweets.size());
            out.setNewerId(tweets.get(0).getId());
            out.setOlderId(tweets.get(tweets.size() - 1).getId());
            if (saveNotifications) {
                setValue("new_tweets_count", getInt("new_tweets_count") + tweets.size());
                save();
            }

            Log.d(Utils.TAG, tweets.size() + " mensajes nuevos en " + getString("name"));

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

            for (int i = tweets.size() - 1; i >= 0; i--) {

                /*String sql = "INSERT INTO 'tweets' ("  + DataFramework.KEY_ID + ", search_id, url_avatar, username, user_id, tweet_id,"
                      + "text, source, to_username, to_user_id, date, favorite) VALUES (" + fisrtId + "," + getId()
                      + ",'" +tweets.get(i).getProfileImageUrl() + "','"+tweets.get(i).getFromUser()+"','"
                      + tweets.get(i).getFromUserId() + "','" + tweets.get(i).getId() + "','" + tweets.get(i).getText() 
                      + "','" + tweets.get(i).getSource()   + "','"+tweets.get(i).getToUser()
                      +"','"+tweets.get(i).getToUserId()+"','"+String.valueOf(tweets.get(i).getCreatedAt().getTime())
                      + "',0);\n";*/
                User u = tweets.get(i).getUser();
                ContentValues args = new ContentValues();
                args.put(DataFramework.KEY_ID, "" + fisrtId);
                args.put("search_id", "" + getId());
                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("" + tweets.get(i).getId()));
                args.put("text", tweets.get(i).getText());
                args.put("source", tweets.get(i).getSource());
                args.put("to_username", tweets.get(i).getInReplyToScreenName());
                args.put("to_user_id", "" + tweets.get(i).getInReplyToUserId());
                args.put("date", String.valueOf(tweets.get(i).getCreatedAt().getTime()));
                if (tweets.get(i).getGeoLocation() != null) {
                    args.put("latitude", tweets.get(i).getGeoLocation().getLatitude());
                    args.put("longitude", tweets.get(i).getGeoLocation().getLongitude());
                }
                args.put("favorite", "0");

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

                fisrtId++;

            }

            if (saveNotifications) {
                setValue("last_tweet_id_notifications", tweets.get(0).getId() + "");
                save();
            }

            int total = nResult + tweets.size();
            if (total > Utils.MAX_ROW_BYSEARCH) {
                Log.d(Utils.TAG, "Limpiando base de datos");
                String date = DataFramework.getInstance()
                        .getEntityList("tweets", "favorite=0 and search_id=" + getId(), "date desc")
                        .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                String sqldelete = "DELETE FROM tweets WHERE favorite=0 AND search_id=" + getId()
                        + " AND date  < '" + date + "'";
                DataFramework.getInstance().getDB().execSQL(sqldelete);
            }

        }

    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.database.EntityTweetUser.java

License:Apache License

public InfoSaveTweets saveTweets(Context context, Twitter twitter) {

    InfoSaveTweets out = new InfoSaveTweets();

    try {/*  w  w  w  . j  ava2 s .c o m*/
        String where = "type_id = " + tweet_type + " AND user_tt_id=" + getId();

        int nResult = DataFramework.getInstance().getEntityListCount("tweets_user", where);
        if (nResult > 0)
            mLastIdNotification = DataFramework.getInstance().getTopEntity("tweets_user", where, "date desc")
                    .getLong("tweet_id");

        boolean breakTimeline = false;

        PreferenceManager.setDefaultValues(context, R.xml.preferences, false);
        SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);

        int maxDownloadTweet = Integer.parseInt(pref.getString("prf_n_max_download", "60"));
        if (maxDownloadTweet <= 0)
            maxDownloadTweet = 60;

        ResponseList<twitter4j.Status> statii = null;
        ResponseList<twitter4j.DirectMessage> directs = null;

        if (mLastIdNotification > 0) {
            if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {

                Paging p = new Paging(1, maxDownloadTweet);
                p.setSinceId(mLastIdNotification);

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

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

            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                statii = twitter.getMentionsTimeline(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getDirectMessages(p);
            } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                Paging p = new Paging();
                p.setCount(100);
                p.setSinceId(mLastIdNotification);
                directs = twitter.getSentDirectMessages(p);
            }
        } else {
            try {
                Log.d(Utils.TAG, "Primera carga de " + getTypeText());
                if (tweet_type == TweetTopicsUtils.TWEET_TYPE_TIMELINE) {
                    statii = twitter.getHomeTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_MENTIONS) {
                    statii = twitter.getMentionsTimeline(new Paging(1, 40));
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_DIRECTMESSAGES) {
                    directs = twitter.getDirectMessages();
                } else if (tweet_type == TweetTopicsUtils.TWEET_TYPE_SENT_DIRECTMESSAGES) {
                    directs = twitter.getSentDirectMessages();
                }
            } catch (OutOfMemoryError e) {
                e.printStackTrace();
            }
        }

        // guardar statii

        if (statii != null) {

            if (statii.size() > 0) {
                out.setNewMessages(statii.size());
                out.setNewerId(statii.get(0).getId());
                out.setOlderId(statii.get(statii.size() - 1).getId());

                Log.d(Utils.TAG,
                        statii.size() + " mensajes nuevos en " + getTypeText() + " de " + getString("name"));

                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;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                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", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            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);

                            out.addId(nextId);

                            nextId++;

                            if (isFirst)
                                isFirst = false;
                        }

                    }

                    // finalizar

                    int total = nResult + statii.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH
                            || total > Utils.MAX_ROW_BYSEARCH_FORCE) {
                        try {
                            Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente "
                                    + total + " registros");
                            String date = DataFramework.getInstance()
                                    .getEntityList("tweets_user",
                                            "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                    .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                            String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                    + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                            DataFramework.getInstance().getDB().execSQL(sqldelete);
                        } catch (OutOfMemoryError e) {
                        }
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }

        // guardar directs

        if (directs != null) {
            if (directs.size() > 0) {
                out.setNewMessages(directs.size());
                out.setNewerId(directs.get(0).getId());
                out.setOlderId(directs.get(directs.size() - 1).getId());

                Log.d(Utils.TAG, directs.size() + " mensajes directos a " + getString("name"));

                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;
                }

                DataFramework.getInstance().getDB().beginTransaction();

                try {
                    for (int i = directs.size() - 1; i >= 0; i--) {
                        User u = directs.get(i).getSender();
                        if (u != null) {
                            ContentValues args = new ContentValues();
                            args.put(DataFramework.KEY_ID, "" + nextId);
                            args.put("type_id", tweet_type);
                            args.put("user_tt_id", "" + getId());
                            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("" + directs.get(i).getId()));
                            args.put("source", "");
                            args.put("to_username", directs.get(i).getRecipientScreenName());
                            args.put("to_user_id", "" + directs.get(i).getRecipientId());
                            args.put("date", String.valueOf(directs.get(i).getCreatedAt().getTime()));
                            args.put("text", directs.get(i).getText());

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

                            out.addId(nextId);

                            Log.d(Utils.TAG,
                                    "getRecipientScreenName: " + directs.get(i).getRecipientScreenName());

                            nextId++;
                        }

                    }

                    // finalizar

                    int total = nResult + directs.size();

                    if (total > Utils.MAX_ROW_BYSEARCH && getValueNewCount() < Utils.MAX_ROW_BYSEARCH) {
                        Log.d(Utils.TAG, "Limpiando base de datos de " + getTypeText() + " actualmente " + total
                                + " registros");
                        String date = DataFramework.getInstance()
                                .getEntityList("tweets_user",
                                        "type_id=" + tweet_type + " and user_tt_id=" + getId(), "date desc")
                                .get(Utils.MAX_ROW_BYSEARCH).getString("date");
                        String sqldelete = "DELETE FROM tweets_user WHERE type_id=" + tweet_type
                                + " and user_tt_id=" + getId() + " AND date  < '" + date + "'";
                        DataFramework.getInstance().getDB().execSQL(sqldelete);
                    }

                    DataFramework.getInstance().getDB().setTransactionSuccessful();

                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DataFramework.getInstance().getDB().endTransaction();
                }

            }

        }
    } catch (TwitterException e) {
        e.printStackTrace();
        RateLimitStatus rate = e.getRateLimitStatus();
        if (rate != null) {
            out.setError(Utils.LIMIT_ERROR);
            out.setRate(rate);
        } else {
            out.setError(Utils.UNKNOWN_ERROR);
        }
    } catch (Exception e) {
        e.printStackTrace();
        out.setError(Utils.UNKNOWN_ERROR);
    }
    return out;
}

From source file:com.javielinux.infos.InfoTweet.java

License:Apache License

public InfoTweet(User user) {
    urls = new ArrayList<URLContent>();
    mTypeFrom = FROM_USER;//from  w w  w  .j  a  v  a 2 s  .  com

    urlAvatar = user.getProfileImageURL().toString();
    userId = user.getId();
    username = user.getScreenName();
    fullname = user.getName();
    try {
        id = user.getStatus().getId();
        text = user.getStatus().getText();
        source = user.getStatus().getSource();
        toUsername = user.getStatus().getInReplyToScreenName();
        toUserId = user.getStatus().getInReplyToUserId();
        createAt = user.getStatus().getCreatedAt();
        toReplyId = user.getStatus().getInReplyToStatusId();
        if (user.getStatus().getGeoLocation() != null) {
            latitude = user.getStatus().getGeoLocation().getLatitude();
            longitude = user.getStatus().getGeoLocation().getLongitude();
        }
    } catch (Exception e) {
    }

    calculateLinks();
}

From source file:com.javielinux.infos.InfoUsers.java

License:Apache License

public InfoUsers(User user) {
    setId(user.getId());/*from   w w  w  . j  a va2 s .  co m*/
    setName(user.getScreenName());
    setFullname(user.getName());
    setCreated(user.getCreatedAt());
    setLocation(user.getLocation());
    if (user.getURL() != null)
        setUrl(user.getURL().toString());
    setFollowers(user.getFollowersCount());
    setFollowing(user.getFriendsCount());
    setTweets(user.getStatusesCount());
    setBio(user.getDescription());
    if (user.getStatus() != null)
        setTextTweet(user.getStatus().getText());
    setUrlAvatar(user.getProfileImageURL().toString());

    ArrayList<Entity> ents = DataFramework.getInstance().getEntityList("users",
            "service is null or service = \"twitter.com\"");

    for (Entity ent : ents) {
        friendly.put(ent.getString("name"), new Friend(ent.getString("name")));
    }

}

From source file:com.k42b3.xoxa.TwitterBot.java

License:Open Source License

public TwitterBot(String host, int port, String nick, String pass, String channel, boolean ssl, int minInterval,
        int maxInterval, String consumerKey, String consumerSecret, String accessToken,
        String accessTokenSecret) {
    super(host, port, nick, pass, channel, ssl, minInterval, maxInterval);

    try {/*from   w w w.  j  av  a2 s . c om*/
        ConfigurationBuilder cb = new ConfigurationBuilder();

        cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessTokenSecret);

        TwitterFactory tf = new TwitterFactory(cb.build());

        this.twitter = tf.getInstance();

        User user = this.twitter.verifyCredentials();

        logger.info("Connected to twitter account " + user.getName());
    } catch (Exception e) {
        logger.warning(e.getMessage());
    }
}