List of usage examples for twitter4j User getId
long getId();
From source file:com.soomla.profile.social.twitter.SoomlaTwitter.java
License:Apache License
private UserProfile createUserProfile(User user, boolean withExtraFields) { String fullName = user.getName(); String firstName = ""; String lastName = ""; if (!TextUtils.isEmpty(fullName)) { String[] splitName = fullName.split(" "); if (splitName.length > 0) { firstName = splitName[0];// w w w .jav a 2 s.c o m if (splitName.length > 1) { lastName = splitName[1]; } } } Map<String, Object> extraDict = Collections.<String, Object>emptyMap(); if (withExtraFields) { extraDict = new HashMap<String, Object>(); // TwitterException will throws when Twitter service or network is unavailable, or the user has not authorized try { extraDict.put("access_token", twitter.getOAuthAccessToken().getToken()); } catch (TwitterException twitterExc) { SoomlaUtils.LogError(TAG, twitterExc.getErrorMessage()); } } //Twitter does not supply email access: https://dev.twitter.com/faq#26 UserProfile result = new UserProfile(RefProvider, String.valueOf(user.getId()), user.getScreenName(), "", firstName, lastName, extraDict); // No gender information on Twitter: // https://twittercommunity.com/t/how-to-find-male-female-accounts-in-following-list/7367 result.setGender(""); // No birthday on Twitter: // https://twittercommunity.com/t/how-can-i-get-email-of-user-if-i-use-api/7019/16 result.setBirthday(""); result.setLanguage(user.getLang()); result.setLocation(user.getLocation()); result.setAvatarLink(user.getBiggerProfileImageURL()); return result; }
From source file:com.tuncaysenturk.jira.plugins.jtp.twitter.JiraTwitterUserStreamListener.java
public void onFollow(User source, User followedUser) { logger.info(JTPConstants.LOG_PRE + "just logging, onFollow source:@" + source.getScreenName() + " target:@" + followedUser.getScreenName()); if (null != followers) followers.add(followedUser.getId()); }
From source file:com.tweetmyhome.TweetMyHome.java
private void integrityCheckSuperAdmin() { try {/*from ww w . j a va 2s. co m*/ User superAdmin = tw.showUser(p.getValueByKey(TweetMyHomeProperties.Key.twitterSuperUser)); long dbSuperAdminId = db.getSuperAdminId(); if (dbSuperAdminId != TweetMyHomeDatabase.NOT_EXIST) { long twitterIdSuperAdmin = superAdmin.getId(); if (twitterIdSuperAdmin != dbSuperAdminId) { db.setSuperUserId(dbSuperAdminId); debug("Updated Super Admin id from twitter...."); } else { debug("Super Admin integrity is correct..."); } db.setSuperUserId(LEVEL_NONE); } else { warn("Super User id in twitter does't found..."); } } catch (TwitterException ex) { warn("Super user acount does't exist. verify your config file or check twitter conection", ex); } }
From source file:com.tweetmyhome.TweetMyHome.java
private void analyzeAndRespond(User user, TweetStringAnalizer tsa, boolean directMessage) throws TwitterException, TweetMyHomeException { String _user = "@" + user.getScreenName(); TweetFlag.Flag flag = tsa.getFlagTweetFlag().getFlag(); TweetFlag.Value value = tsa.getFlagTweetFlag().getValue(); StringBuilder finalTweetStringResponse = new StringBuilder(); boolean error = false; boolean private_message = false; boolean informar_admins = false;//************************************************ switch (flag) { case ALARM://from ww w . j ava 2s . c o m if (value.equals(TweetFlag.Value.ON)) { if (!sec.isEnabled()) { // activo la alarma finalTweetStringResponse.append(_user).append(" Alarma Activada! ").append(TENDENCE); sec.enable(); db.add(new HistorySecurity(sec.isEnabled(), Calendar.getInstance().getTimeInMillis(), user.getId())); } else { // la alarma ya esta activada. envio mensaje de error privado al usuario private_message = true; finalTweetStringResponse.append("Error,la alarma ya esta activa"); } } else if (value.equals(TweetFlag.Value.OFF)) { if (sec.isEnabled()) { // desactivo la alarma finalTweetStringResponse.append(_user).append(" Alarma Desactivada! ").append(TENDENCE); sec.disable(); db.add(new HistorySecurity(sec.isEnabled(), Calendar.getInstance().getTimeInMillis(), user.getId())); } else { // alarma ya desactivada. envio mensaje de error privado al usuario private_message = true; finalTweetStringResponse.append("Error,la alarma ya esta desactivada"); } } else if (value.equals(TweetFlag.Value.STATUS)) { private_message = true; if (sec.isEnabled()) { finalTweetStringResponse.append("Alarma activa "); } else { finalTweetStringResponse.append("Alarma desactivada "); } finalTweetStringResponse.append(TENDENCE); } else { error = true; warn("Alarm value does't founded"); } break; case COMUNITY: if (value.equals(TweetFlag.Value.ON)) { if (!com.isActivated()) { //activo modo comunitario finalTweetStringResponse.append(_user).append(" Modo comunitario activado! ") .append(TENDENCE); com.activateComunityMode(); db.add(new HistoryComunityMode(com.isActivated(), Calendar.getInstance().getTimeInMillis(), user.getId())); } else { private_message = true; finalTweetStringResponse.append("Error, el modo comunitario ya esta activado"); } } else if (value.equals(TweetFlag.Value.OFF)) { if (com.isActivated()) { finalTweetStringResponse.append(_user).append(" Modo comunitario desactivado! ") .append(TENDENCE); com.desactivateComunityMode(); db.add(new HistoryComunityMode(com.isActivated(), Calendar.getInstance().getTimeInMillis(), user.getId())); } else { private_message = true; finalTweetStringResponse.append("Error, el modo comunitario ya esta desactivado"); } } else { error = true; warn("Comunity value does't founded"); } break; case USER: private_message = true; if (value.equals(TweetFlag.Value.ADD)) { // verificar si usuario existe***************************** tsa.getTweetVariableList().forEach(v -> { debug(" Tweet Variables founded"); debug("\t" + "[" + v.getVaribleIdentifier() + "]" + v.getVariable()); }); String newAddUserName = tsa.getTweetVariableList().get(0).getVariable(); User twitterUser = tw.showUser(newAddUserName); db.add(new TwitterUser(twitterUser.getId(), TwitterUserUtil.getTwitterUser(newAddUserName), UserRol.user, true)); finalTweetStringResponse.append(_user).append(" Usuario Aadido! ").append(TENDENCE); } else if (value.equals(TweetFlag.Value.DEL)) { String newDelUser = tsa.getTweetVariableList().get(0).getVariable(); // solo deberia existir 1 elemento User twitterUser = tw.showUser(newDelUser); db.desactivateUserById(twitterUser.getId()); tw.destroyFriendship(twitterUser.getId()); // ver este metodo en accion.. la idea es dejar de seguir************* finalTweetStringResponse.append(_user).append(" Usuario Eliminado! ").append(TENDENCE); } else if (value.equals(TweetFlag.Value.MOD)) { // farta******************************************* //diferente finalTweetStringResponse.append(_user).append(" Usuario Modificado! ").append(TENDENCE); } else { error = true; warn("User value does't founded"); } break; case NULL: default: error = true; warn("Flag value does't founded"); } debug("analizeAndRespond[finalTweetStringResponse]=" + finalTweetStringResponse.toString()); if (!error) { // el usuario es la casa misma plix finalTweetStringResponse.append(" ").append(tweetCount.getHexHashTagCount()); if (directMessage) { // respondo solo al usuario ya que es un mensaje directo sendDm(user.getId(), finalTweetStringResponse.toString()); } else if (private_message) { // es de el tipo privado ej:usuario modificado sendDm(user.getId(), finalTweetStringResponse.toString()); } else if (com.isActivated()) { // en caso de estar modo comunitario lo envio a todos sendT(finalTweetStringResponse.toString()); } else {// Esto solo acurre cuand otengo que informar algo importante pero no esta el modo comunitario activado // envio mensajes privados a todos los usuarios "amigos". a partir de la bd para menor conjestion for (TwitterUser u : db.getAllUsers()) { // a que tipo de usuario se lo envio !?!?!??!--------- if (u.isActivado()) { sendDm(u.getIdTwitterUser(), finalTweetStringResponse.toString()); } } } } else { throw new TweetMyHomeException("Error Flag or Values does not match or are invalid"); } }
From source file:com.twitstreet.db.data.Stock.java
License:Open Source License
public Stock(twitter4j.User twUser) { this.setId(twUser.getId()); this.setLongName(twUser.getName()); this.setName(twUser.getScreenName()); this.setTotal(twUser.getFollowersCount()); this.setPictureUrl(twUser.getProfileImageURL().toExternalForm()); this.setSold(0.0D); this.setVerified(twUser.isVerified()); this.setLanguage(twUser.getLang()); this.setCreatedAt(twUser.getCreatedAt()); this.setLocation(twUser.getLocation()); this.setDescription(twUser.getDescription()); }
From source file:com.twitstreet.twitter.FollowBackMgrImpl.java
License:Open Source License
@Override public void start() { Announcer announcer = announcerMgr.randomAnnouncerData(); twitterProxy = twitterProxyFactory.create(announcer.getAccessToken(), announcer.getAccessTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterStream.setOAuthConsumer(announcer.getConsumerKey(), announcer.getConsumerSecret()); twitterStream/* w w w . j ava 2 s . c o m*/ .setOAuthAccessToken(new AccessToken(announcer.getAccessToken(), announcer.getAccessTokenSecret())); twitterStream.addListener(new StatusListener() { @Override public void onException(Exception arg0) { } @Override public void onTrackLimitationNotice(int arg0) { } @Override public void onStatus(Status status) { if (System.currentTimeMillis() - lastFollow > FOLLOW_INTERVAL) { twitter4j.User user = status.getUser(); announcerMgr.follow(user.getId()); lastFollow = System.currentTimeMillis(); } // if(System.currentTimeMillis() - lastFollowDiabloBird > FOLLOW_INTERVAL/6){ // twitter4j.User user = status.getUser(); // announcerMgr.followForDiabloBird(user.getId()); // lastFollowDiabloBird = System.currentTimeMillis(); // } } @Override public void onScrubGeo(long arg0, long arg1) { } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { } }); FilterQuery filterQuery = new FilterQuery(); filterQuery.count(0); filterQuery.track(FILTER_TERMS); twitterStream.filter(filterQuery); }
From source file:com.twitstreet.twitter.SimpleTwitterUser.java
License:Open Source License
public SimpleTwitterUser(User user) { this.id = user.getId(); this.screenName = user.getScreenName(); this.pictureUrl = user.getProfileImageURL().toExternalForm(); this.followerCount = user.getFollowersCount(); this.verified = user.isVerified(); }
From source file:com.twitstreet.twitter.TwitterProxyImpl.java
License:Open Source License
private void handleError(TwitterException e, ArrayList<Object> params) { String paramsStr = ""; if (params != null) { for (Object obj : params) { paramsStr = paramsStr + obj.toString() + ", "; }/* w w w.j av a2 s. co m*/ } if (e.getStatusCode() == NOT_FOUND) { logger.debug("Twitter: User not found. Params: " + paramsStr); } else if (e.getStatusCode() == USER_SUSPENDED) { logger.info("Twitter: User suspended. Params: " + paramsStr); } else if (e.getStatusCode() == TWITTER_SERVERS_OVERLOADED) { logger.info("Twitter: The Twitter servers are up, but overloaded with requests. Try again later."); } else if (e.getStatusCode() == RATE_LIMIT_EXCEEDED) { logger.error("Twitter: Rate limit exceeded."); } else if (e.getStatusCode() == UNAUTHORIZED) { logger.error("Twitter: Authentication credentials were missing or incorrect. Token: " + oToken + ", Secret: " + oSecret); com.twitstreet.db.data.User user = userMgr.getUserByTokenAndSecret(oToken, oSecret); userMgr.deleteUser(user.getId()); } else if (e.getStatusCode() == INVALID_REQUEST) { logger.error( "Twitter: The request was invalid. Possible reason: Query string may be including empty character. "); } else { logger.error("Twitter: Unhandled twitter exception.", e); } }
From source file:com.twitt4droid.data.dao.impl.sqlite.UserSQLiteDAO.java
License:Apache License
/** {@inheritDoc} */ @Override//from w ww . jav a 2 s . c o m public void save(User user) { getSQLiteTemplate().execute(getSqlString(R.string.twitt4droid_insert_user_sql), new String[] { Objects.toString(user.getId()), user.getName(), user.getScreenName(), user.getProfileImageURL(), user.getProfileBannerURL(), user.getURL(), user.getDescription(), user.getLocation() }); }
From source file:com.twitt4droid.data.dao.impl.sqlite.UserSQLiteDAO.java
License:Apache License
/** {@inheritDoc} */ @Override//from w ww . ja v a 2 s .c om public void delete(User user) { getSQLiteTemplate().execute(getSqlString(R.string.twitt4droid_delete_user_by_id_sql), new String[] { Objects.toString(user.getId()) }); }