List of usage examples for twitter4j User getId
long getId();
From source file:com.klinker.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getFollowing(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;//from w w w.ja va 2s.c o m new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); PagableResponseList<User> friendsPaging; try { friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing); } catch (OutOfMemoryError e) { return; } for (int i = 0; i < friendsPaging.size(); i++) { following.add(friendsPaging.get(i)); Log.v("friends_list", friendsPaging.get(i).getName()); } if (friendsPaging.size() > 17) { hasMore = true; } else { hasMore = false; } currentFollowing = friendsPaging.getNextCursor(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (followingAdapter == null) { followingAdapter = new PeopleArrayAdapter(context, following); listView.setAdapter(followingAdapter); } else { followingAdapter.notifyDataSetChanged(); } if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); canRefresh = true; spinner.setVisibility(View.GONE); } }); } catch (Exception e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { try { if (user != null && user.isProtected()) { Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); } else { Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show(); } spinner.setVisibility(View.GONE); } catch (Exception e) { // fragment not attached } canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:com.marpies.ane.twitter.utils.UserUtils.java
License:Apache License
public static JSONObject getJSON(User user) throws JSONException { JSONObject userJSON = new JSONObject(); userJSON.put("id", user.getId()); userJSON.put("screenName", user.getScreenName()); userJSON.put("name", user.getName()); userJSON.put("createdAt", user.getCreatedAt()); userJSON.put("description", user.getDescription()); userJSON.put("tweetsCount", user.getStatusesCount()); userJSON.put("likesCount", user.getFavouritesCount()); userJSON.put("followersCount", user.getFollowersCount()); userJSON.put("friendsCount", user.getFriendsCount()); userJSON.put("profileImageURL", user.getProfileImageURL()); userJSON.put("isProtected", user.isProtected()); userJSON.put("isVerified", user.isVerified()); userJSON.put("location", user.getLocation()); return userJSON; }
From source file:com.mastfrog.acteur.twitter.TwitterSign.java
RemoteUserInfo getUserInfo(String oauth_nonce, TwitterOAuthPlugin.TwitterToken credential, AuthorizationResponse auth)//w ww . j a v a 2 s . co m throws UnsupportedEncodingException, GeneralSecurityException, InterruptedException, IOException { // System.setProperty("twitter4j.loggerFactory", "twitter4j.internal.logging.StdOutLogger"); System.setProperty("twitter4j.debug", "true"); System.setProperty("twitter4j.http.useSSL", "false"); Twitter twitter = TwitterFactory.getSingleton(); try { // Idiotic twitter.setOAuthConsumer(twitter_consumer_key, twitter_consumer_secret); } catch (Exception e) { e.printStackTrace(); } twitter.setOAuthAccessToken(new AccessToken(auth.accessToken, auth.accessTokenSecret)); try { User user = twitter.verifyCredentials(); RUI rui = new RUI(); rui.put("displayName", user.getName()); rui.put("name", user.getScreenName() + "@api.twitter.com"); rui.put("screen_name", user.getScreenName()); rui.put("picture", user.getProfileImageURLHttps()); rui.put("pictureLarge", user.getBiggerProfileImageURLHttps()); rui.put("id", user.getId()); return rui; } catch (TwitterException ex) { throw new IOException(ex); } finally { twitter.shutdown(); } }
From source file:com.metadot.book.connectr.server.servlets.LoginTwitterCallbackServlet.java
License:Apache License
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { Twitter twitter = new TwitterFactory().getInstance(); String key = AuthenticationProvider.getProp("twitter-consumer-key"); String secret = AuthenticationProvider.getProp("twitter-consumer-secret"); RequestToken token = (RequestToken) request.getSession().getAttribute("requestToken"); String verifier = request.getParameter("oauth_verifier"); twitter.setOAuthConsumer(key, secret); try {/*from w w w . j a va2 s . c o m*/ twitter.getOAuthAccessToken(token, verifier); User user = twitter.verifyCredentials(); log.info("Twitter user found:" + user.getName()); request.getSession().removeAttribute("requestToken"); String sid = ((Integer) user.getId()).toString(); UserAccount u = new UserAccount(sid, AuthenticationProvider.TWITTER); // use screen name for uid u.setName(user.getScreenName()); UserAccount connectr = new LoginHelper().loginStarts(request.getSession(), u); log.info("User id:" + connectr.getId().toString()); } catch (TwitterException e) { e.printStackTrace(); } response.sendRedirect(LoginHelper.getApplitionURL(request)); }
From source file:com.narvis.frontend.twitter.input.Input.java
License:Open Source License
@Override public void onFavorite(User source, User target, Status favoritedStatus) { NarvisLogger.logInfo("Received fav notice from user : " + source.getId() + " to user : " + target.getId() + " to following message : " + favoritedStatus.getText()); }
From source file:com.narvis.frontend.twitter.input.Input.java
License:Open Source License
@Override public void onUnfavorite(User source, User target, Status unfavoritedStatus) { NarvisLogger.logInfo("Received unfav notice from user : " + source.getId() + " to user : " + target.getId() + " to following message : " + unfavoritedStatus.getText()); }
From source file:com.narvis.frontend.twitter.input.Input.java
License:Open Source License
@Override public void onFollow(User source, User followedUser) { NarvisLogger.logInfo("Received follow notice from user : " + source.getId() + " to followed user : " + followedUser.getId());/*from w ww .j av a2s . c o m*/ }
From source file:com.narvis.frontend.twitter.input.Input.java
License:Open Source License
@Override public void onUnfollow(User source, User unfollowedUser) { NarvisLogger.logInfo("Received unfollow notice from user : " + source.getId() + " to followed user : " + unfollowedUser.getId());//from w w w . ja v a 2s.c om }
From source file:com.projectlaver.util.TwitterListingResponseHandler.java
License:Open Source License
public void processStatus(Status status) { if (this.logger.isDebugEnabled()) { this.logger.debug("+processStatus() with status id: " + status.getId()); }// ww w . j a v a2 s.co m String twitterId = this.longToString(status.getId()); User profile = status.getUser(); // Convert twitterIds to Strings here because these fields are treated as varchars by the database String providerUserId = this.longToString(profile.getId()); String inReplyToStatusId = this.longToString(status.getInReplyToStatusId()); String tweetText = status.getText(); Boolean isRetweet = (status.getRetweetedStatus() != null); // these two fields are required; without an @mention and a #hashtag we do not need to persist this tweet String mentionedProviderUserId = this.getMentionedProviderUserId(status.getUserMentionEntities()); String hashtag = this.getMentionedHashtag(status.getHashtagEntities()); if (StringUtils.isNoneBlank(mentionedProviderUserId, hashtag)) { ReplyMessageDTO dto = new ReplyMessageDTO(SocialProviders.TWITTER, providerUserId, twitterId, inReplyToStatusId, null, isRetweet, tweetText, hashtag, INITIAL_STATUS, status.getCreatedAt()); // Use a try catch here to trap excptions try { super.processUserMessage(mentionedProviderUserId, dto, false); // Retry on deadlock } catch (DeadlockLoserDataAccessException e) { this.logger.error("Lost deadlock trying to insert tweet. Falling back on retry logic."); this.retryProcessAfterDeadlock(mentionedProviderUserId, dto); // Log on uncaught exception } catch (Exception e) { this.logger.error(String.format( "Valid message with id: %s read by stream, but processing failed with an exception.", twitterId), e); this.logger.error("UNINSERTED TWEET: " + ToStringBuilder.reflectionToString(dto)); } } if (this.logger.isDebugEnabled()) { this.logger.debug("-processStatus() with status id: " + status.getId()); } }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) {//from w w w .j a va 2 s . c o m TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName); result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }