List of usage examples for twitter4j User getName
String getName();
From source file:org.kawalpemilukada.login.login.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j av a 2 s .c o m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String form_action = request.getParameter("form_action"); if (form_action == null) { form_action = ""; } PrintWriter out = response.getWriter(); if (form_action.equalsIgnoreCase("loginfb")) { String tahun = request.getParameter("tahun"); if (tahun == null) { tahun = ""; } Facebook facebook = new FacebookFactory().getInstance(); request.getSession().setAttribute("facebook", facebook); request.getSession().setAttribute("tahun", tahun); StringBuffer callbackURL = request.getRequestURL(); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/callbackfb"); response.sendRedirect(facebook.getOAuthAuthorizationURL(callbackURL.toString()) + "&display=popup"); } if (form_action.equalsIgnoreCase("logintwit")) { String tahun = request.getParameter("tahun"); if (tahun == null) { tahun = ""; } Twitter twitter = new TwitterFactory().getInstance(); request.getSession().setAttribute("twitter", twitter); request.getSession().setAttribute("tahun", tahun); String rurl = request.getParameter("rurl"); StringBuffer callbackURL = request.getRequestURL(); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/callbackTwit?rurl=" + rurl); try { RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); request.getSession().setAttribute("requestToken", requestToken); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { request.getSession().removeAttribute("twitter"); request.getSession().removeAttribute("tahun"); } } if (form_action.equalsIgnoreCase("loginmobiletwit")) { String t = "twit"; UserData user = CommonServices.getUser(request); LinkedHashMap record = new LinkedHashMap(); Gson gson = new Gson(); StringBuffer sb = new StringBuffer(); String line = null; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject input = (JSONObject) JSONValue.parse(sb.toString()); if (user == null) { try { JSONObject twit = (JSONObject) input.get("user"); String id = CommonServices.getVal(twit.get("id")); id = id.replaceAll(t, ""); user = ofy().load().type(UserData.class).id(t + id).now(); if (user == null) { String accessToken = CommonServices.getVal(twit.get("token")); String accessTokenSecret = CommonServices.getVal(twit.get("secret")); String consumerKey = new CommonServices().getPropValues("kpu.properties", "consumerKey", request); String consumerSecret = new CommonServices().getPropValues("kpu.properties", "consumerSecret", request); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setOAuthAccessToken(accessToken) .setOAuthAccessTokenSecret(accessTokenSecret); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User u = twitter.showUser(twitter.getId()); user = new UserData("twit" + CommonServices.getVal(twitter.getId())); user.imgurl = u.getBiggerProfileImageURLHttps().replace("http://", "https://"); user.nama = CommonServices.getVal(u.getName()); user.link = "https://twitter.com/" + CommonServices.getVal(twitter.getScreenName()); user.email = ""; user.uuid = CommonServices.getVal(twit.get("uuid")); user.type = t; ofy().save().entity(user).now(); Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0")); Dashboard dashboard2014 = CommonServices .getDashboard(CommonServices.setParentId("2014", "0")); dashboard.users = CommonServices.getuserSize() + ""; ofy().save().entity(dashboard).now(); dashboard2014.users = dashboard.users + ""; ofy().save().entity(dashboard2014).now(); } else { user.lastlogin = CommonServices.JakartaTime(); user.uuid = CommonServices.getVal(twit.get("uuid")); if (user.link.equalsIgnoreCase("https://twitter.com/kawalpemilukada") || user.link.equalsIgnoreCase( "https://www.facebook.com/app_scoped_user_id/10153164750839760/")) { user.userlevel = 100000000; } ofy().save().entity(user).now(); } request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user))); MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid); JSONObject device = (JSONObject) input.get("device"); mobileSession.platform = CommonServices.getVal(device.get("platform")); mobileSession.version = CommonServices.getVal(device.get("version")); mobileSession.cordova = CommonServices.getVal(device.get("cordova")); mobileSession.model = CommonServices.getVal(device.get("model")); mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer")); mobileSession.appversion = CommonServices.getVal(device.get("appversion")); ofy().save().entity(mobileSession).now(); record.put("sessionid", mobileSession.uuid); } catch (Exception e) { } record.put("sumber", "bukan dari session"); } else { MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid); JSONObject device = (JSONObject) input.get("device"); mobileSession.platform = CommonServices.getVal(device.get("platform")); mobileSession.version = CommonServices.getVal(device.get("version")); mobileSession.cordova = CommonServices.getVal(device.get("cordova")); mobileSession.model = CommonServices.getVal(device.get("model")); mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer")); mobileSession.appversion = CommonServices.getVal(device.get("appversion")); ofy().save().entity(mobileSession).now(); record.put("sessionid", mobileSession.uuid); record.put("sumber", "dari session"); } record.put("user", JSONValue.parse(gson.toJson(user))); response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("loginmobilefb")) { UserData user = CommonServices.getUser(request); LinkedHashMap record = new LinkedHashMap(); Gson gson = new Gson(); StringBuffer sb = new StringBuffer(); String line = null; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject input = (JSONObject) JSONValue.parse(sb.toString()); if (user == null) { String t = "fb"; JSONObject fb = (JSONObject) input.get("user"); String id = CommonServices.getVal(fb.get("id")); id = id.replaceAll(t, ""); try { user = ofy().load().type(UserData.class).id(t + id).now(); if (user == null) { user = new UserData("fb" + CommonServices.getVal(fb.get("id"))); user.imgurl = "https://graph.facebook.com/" + fb.get("id") + "/picture"; user.nama = CommonServices.getVal(fb.get("name")); user.link = CommonServices.getVal(fb.get("link")); user.email = CommonServices.getVal(fb.get("email")); user.type = t; user.uuid = CommonServices.getVal(fb.get("uuid")); ofy().save().entity(user).now(); Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0")); Dashboard dashboard2014 = CommonServices .getDashboard(CommonServices.setParentId("2014", "0")); dashboard.users = CommonServices.getuserSize() + ""; ofy().save().entity(dashboard).now(); dashboard2014.users = dashboard.users + ""; ofy().save().entity(dashboard2014).now(); } else { user.lastlogin = CommonServices.JakartaTime(); user.uuid = CommonServices.getVal(fb.get("uuid")); if (user.link.equalsIgnoreCase("https://twitter.com/kawalpemilukada") || user.link.equalsIgnoreCase( "https://www.facebook.com/app_scoped_user_id/10153164750839760/")) { user.userlevel = 100000000; } ofy().save().entity(user).now(); } request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user))); MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid); JSONObject device = (JSONObject) input.get("device"); mobileSession.platform = CommonServices.getVal(device.get("platform")); mobileSession.version = CommonServices.getVal(device.get("version")); mobileSession.cordova = CommonServices.getVal(device.get("cordova")); mobileSession.model = CommonServices.getVal(device.get("model")); mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer")); mobileSession.appversion = CommonServices.getVal(device.get("appversion")); ofy().save().entity(mobileSession).now(); record.put("sessionid", mobileSession.uuid); } catch (Exception e) { } record.put("sumber", "bukan dari session"); } else { record.put("sumber", "dari session"); MobileSession mobileSession = new MobileSession(user.uid + "#" + user.uuid); JSONObject device = (JSONObject) input.get("device"); mobileSession.platform = CommonServices.getVal(device.get("platform")); mobileSession.version = CommonServices.getVal(device.get("version")); mobileSession.cordova = CommonServices.getVal(device.get("cordova")); mobileSession.model = CommonServices.getVal(device.get("model")); mobileSession.manufacturer = CommonServices.getVal(device.get("manufacturer")); mobileSession.appversion = CommonServices.getVal(device.get("appversion")); ofy().save().entity(mobileSession).now(); record.put("sessionid", mobileSession.uuid); } record.put("user", JSONValue.parse(gson.toJson(user))); response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("cekauth")) { UserData user = CommonServices.getUser(request); LinkedHashMap record = new LinkedHashMap(); Gson gson = new Gson(); if (user == null) { record.put("status", "belum login"); } else { record.put("user", JSONValue.parse(gson.toJson(user))); if (user.terverifikasi.equalsIgnoreCase("Y")) { record.put("status", "terverifikasi"); } else { record.put("status", "Data Anda belum terverifikasi."); } } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } if (form_action.equalsIgnoreCase("verifikasi")) { LinkedHashMap record = new LinkedHashMap(); StringBuffer sb = new StringBuffer(); String line = null; BufferedReader reader = request.getReader(); while ((line = reader.readLine()) != null) { sb.append(line); } JSONArray input = (JSONArray) JSONValue.parse(sb.toString()); String nama = ""; String jenis_kelamin = ""; String no_tps = ""; try { String url = new CommonServices().getPropValues("kpu.properties", "verifikasiURL", request); String inputx = getWeb(url + input.get(0).toString()); JSONObject data = (JSONObject) JSONValue.parse(inputx); nama = data.get("nama").toString(); jenis_kelamin = data.get("jenis_kelamin").toString(); } catch (Exception e) { nama = ""; } if (nama == null || nama.equalsIgnoreCase("")) { try { String url = new CommonServices().getPropValues("kpu.properties", "verifikasiURL2015", request); String inputx = getWeb(url + input.get(0).toString()); LinkedHashMap data = getJsonNik(inputx); nama = data.get("nama").toString(); jenis_kelamin = data.get("jenis kelamin").toString(); no_tps = data.get("no_tps").toString(); } catch (Exception e) { nama = ""; } } JSONArray matchs = new JSONArray(); if (nama.equalsIgnoreCase(input.get(1).toString())) { UserData user = CommonServices.getUser(request); double match = 0; //if (data.get("nama").toString().equalsIgnoreCase(user.nama)) { //match = 100; //} else { String[] sosialnamaParts = user.nama.toString().split(" "); String[] namaParts = nama.toString().split(" "); int dibagi = sosialnamaParts.length; if (namaParts.length > dibagi) { dibagi = namaParts.length; } double increase = 100 / dibagi; String iiString = ""; for (int i = 0; i < namaParts.length; i++) { String namaPart = namaParts[i]; for (int ii = 0; ii < sosialnamaParts.length; ii++) { String fbnamaPart = sosialnamaParts[ii]; if (namaPart.equalsIgnoreCase(fbnamaPart) && (!iiString.contains(ii + ""))) { match = match + increase; matchs.add(namaPart + " sesuai dengan " + fbnamaPart); iiString = iiString + "[" + ii + "]"; break; } } } // } if (match > 100) { match = 100; } if (match >= 60) { user.terverifikasi = "Y"; user.notps = no_tps; ObjectifyService.ofy().save().entity(user).now(); Gson gson = new Gson(); record.put("user", JSONValue.parse(gson.toJson(user))); } record.put("status", match + ""); record.put("matchs", matchs); } else { record.put("status", "Data NIK: " + input.get(0).toString() + " dan Nama: " + input.get(1).toString() + " tidak ditemukan."); } response.setContentType("text/html;charset=UTF-8"); out.print(JSONValue.toJSONString(record)); out.flush(); } }
From source file:org.keycloak.social.twitter.TwitterProvider.java
License:Open Source License
@Override public SocialUser processCallback(SocialProviderConfig config, AuthCallback callback) throws SocialProviderException { if (callback.getQueryParam("denied") != null) { throw new SocialAccessDeniedException(); }//w w w.j a v a 2 s .co m try { Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(config.getKey(), config.getSecret()); String token = callback.getQueryParam("oauth_token"); String verifier = callback.getQueryParam("oauth_verifier"); RequestToken requestToken = new RequestToken((String) callback.getAttribute("token"), (String) callback.getAttribute("tokenSecret")); twitter.getOAuthAccessToken(requestToken, verifier); twitter4j.User twitterUser = twitter.verifyCredentials(); SocialUser user = new SocialUser(Long.toString(twitterUser.getId()), twitterUser.getScreenName()); user.setName(twitterUser.getName()); return user; } catch (Exception e) { throw new SocialProviderException(e); } }
From source file:org.mariotaku.twidere.model.ParcelableStatus.java
License:Open Source License
public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) { this.is_gap = is_gap; this.account_id = account_id; id = orig.getId();//from ww w .j a va 2 s. c o m timestamp = getTime(orig.getCreatedAt()); final Status retweeted = orig.getRetweetedStatus(); final User retweet_user = retweeted != null ? orig.getUser() : null; is_retweet = orig.isRetweet(); retweet_id = retweeted != null ? retweeted.getId() : -1; retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1; retweeted_by_user_id = retweet_user != null ? retweet_user.getId() : -1; retweeted_by_user_name = retweet_user != null ? retweet_user.getName() : null; retweeted_by_user_screen_name = retweet_user != null ? retweet_user.getScreenName() : null; retweeted_by_user_profile_image = retweet_user != null ? retweet_user.getProfileImageUrlHttps() : null; final Status quoted = orig.getQuotedStatus(); final User quote_user = quoted != null ? orig.getUser() : null; is_quote = orig.isQuote(); quote_id = quoted != null ? quoted.getId() : -1; quote_text_html = TwitterContentUtils.formatStatusText(orig); quote_text_plain = orig.getText(); quote_text_unescaped = HtmlEscapeHelper.toPlainText(quote_text_html); quote_timestamp = orig.getCreatedAt().getTime(); quote_source = orig.getSource(); quoted_by_user_id = quote_user != null ? quote_user.getId() : -1; quoted_by_user_name = quote_user != null ? quote_user.getName() : null; quoted_by_user_screen_name = quote_user != null ? quote_user.getScreenName() : null; quoted_by_user_profile_image = quote_user != null ? quote_user.getProfileImageUrlHttps() : null; quoted_by_user_is_protected = quote_user != null && quote_user.isProtected(); quoted_by_user_is_verified = quote_user != null && quote_user.isVerified(); final Status status; if (quoted != null) { status = quoted; } else if (retweeted != null) { status = retweeted; } else { status = orig; } final User user = status.getUser(); user_id = user.getId(); user_name = user.getName(); user_screen_name = user.getScreenName(); user_profile_image_url = user.getProfileImageUrlHttps(); user_is_protected = user.isProtected(); user_is_verified = user.isVerified(); user_is_following = user.isFollowing(); text_html = TwitterContentUtils.formatStatusText(status); media = ParcelableMedia.fromStatus(status); quote_media = quoted != null ? ParcelableMedia.fromStatus(orig) : null; text_plain = status.getText(); retweet_count = status.getRetweetCount(); favorite_count = status.getFavoriteCount(); reply_count = status.getReplyCount(); descendent_reply_count = status.getDescendentReplyCount(); in_reply_to_name = TwitterContentUtils.getInReplyToName(retweeted != null ? retweeted : orig); in_reply_to_screen_name = (retweeted != null ? retweeted : orig).getInReplyToScreenName(); in_reply_to_status_id = (retweeted != null ? retweeted : orig).getInReplyToStatusId(); in_reply_to_user_id = (retweeted != null ? retweeted : orig).getInReplyToUserId(); source = status.getSource(); location = ParcelableLocation.fromGeoLocation(status.getGeoLocation()); is_favorite = status.isFavorited(); text_unescaped = HtmlEscapeHelper.toPlainText(text_html); my_retweet_id = retweeted_by_user_id == account_id ? id : status.getCurrentUserRetweet(); is_possibly_sensitive = status.isPossiblySensitive(); mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities()); card = ParcelableCardEntity.fromCardEntity(status.getCard(), account_id); place_full_name = getPlaceFullName(status.getPlace()); card_name = card != null ? card.name : null; }
From source file:org.mariotaku.twidere.model.ParcelableUser.java
License:Open Source License
public ParcelableUser(final User user, final long account_id, final long position) { this.position = position; this.account_id = account_id; final URLEntity[] urls_url_entities = user.getURLEntities(); id = user.getId();/*from ww w. j av a 2 s . co m*/ created_at = user.getCreatedAt().getTime(); is_protected = user.isProtected(); is_verified = user.isVerified(); name = user.getName(); screen_name = user.getScreenName(); description_plain = user.getDescription(); description_html = TwitterContentUtils.formatUserDescription(user); description_expanded = TwitterContentUtils.formatExpandedUserDescription(user); description_unescaped = HtmlEscapeHelper.toPlainText(description_html); location = user.getLocation(); profile_image_url = user.getProfileImageUrlHttps(); profile_banner_url = user.getProfileBannerImageUrl(); url = user.getURL(); url_expanded = url != null && urls_url_entities != null && urls_url_entities.length > 0 ? urls_url_entities[0].getExpandedURL() : null; is_follow_request_sent = user.isFollowRequestSent(); followers_count = user.getFollowersCount(); friends_count = user.getFriendsCount(); statuses_count = user.getStatusesCount(); favorites_count = user.getFavouritesCount(); listed_count = user.getListedCount(); media_count = user.getMediaCount(); is_following = user.isFollowing(); background_color = ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0); link_color = ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0); text_color = ParseUtils.parseColor("#" + user.getProfileTextColor(), 0); is_cache = false; is_basic = false; }
From source file:org.mariotaku.twidere.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createCachedUser(final User user) { if (user == null || user.getId() <= 0) return null; final String profile_image_url = user.getProfileImageUrlHttps(); final String url = user.getURL(); final URLEntity[] urls = user.getURLEntities(); final ContentValues values = new ContentValues(); values.put(CachedUsers.USER_ID, user.getId()); values.put(CachedUsers.NAME, user.getName()); values.put(CachedUsers.SCREEN_NAME, user.getScreenName()); values.put(CachedUsers.PROFILE_IMAGE_URL, profile_image_url); values.put(CachedUsers.PROFILE_BANNER_URL, user.getProfileBannerImageUrl()); values.put(CachedUsers.CREATED_AT, user.getCreatedAt().getTime()); values.put(CachedUsers.IS_PROTECTED, user.isProtected()); values.put(CachedUsers.IS_VERIFIED, user.isVerified()); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); values.put(CachedUsers.FAVORITES_COUNT, user.getFavouritesCount()); values.put(CachedUsers.FOLLOWERS_COUNT, user.getFollowersCount()); values.put(CachedUsers.FRIENDS_COUNT, user.getFriendsCount()); values.put(CachedUsers.STATUSES_COUNT, user.getStatusesCount()); values.put(CachedUsers.LISTED_COUNT, user.getListedCount()); values.put(CachedUsers.MEDIA_COUNT, user.getMediaCount()); values.put(CachedUsers.LOCATION, user.getLocation()); values.put(CachedUsers.DESCRIPTION_PLAIN, user.getDescription()); values.put(CachedUsers.DESCRIPTION_HTML, TwitterContentUtils.formatUserDescription(user)); values.put(CachedUsers.DESCRIPTION_EXPANDED, TwitterContentUtils.formatExpandedUserDescription(user)); values.put(CachedUsers.URL, url); if (url != null && urls != null && urls.length > 0) { values.put(CachedUsers.URL_EXPANDED, urls[0].getExpandedURL()); }//www.j av a2s. c om values.put(CachedUsers.BACKGROUND_COLOR, ParseUtils.parseColor("#" + user.getProfileBackgroundColor(), 0)); values.put(CachedUsers.LINK_COLOR, ParseUtils.parseColor("#" + user.getProfileLinkColor(), 0)); values.put(CachedUsers.TEXT_COLOR, ParseUtils.parseColor("#" + user.getProfileTextColor(), 0)); return values; }
From source file:org.mariotaku.twidere.util.ContentValuesCreator.java
License:Open Source License
public static ContentValues createDirectMessage(final DirectMessage message, final long accountId, final boolean isOutgoing) { if (message == null) return null; final ContentValues values = new ContentValues(); final User sender = message.getSender(), recipient = message.getRecipient(); if (sender == null || recipient == null) return null; final String sender_profile_image_url = sender.getProfileImageUrlHttps(); final String recipient_profile_image_url = recipient.getProfileImageUrlHttps(); values.put(DirectMessages.ACCOUNT_ID, accountId); values.put(DirectMessages.MESSAGE_ID, message.getId()); values.put(DirectMessages.MESSAGE_TIMESTAMP, message.getCreatedAt().getTime()); values.put(DirectMessages.SENDER_ID, sender.getId()); values.put(DirectMessages.RECIPIENT_ID, recipient.getId()); if (isOutgoing) { values.put(DirectMessages.CONVERSATION_ID, recipient.getId()); } else {/*from w ww. j a v a 2s . co m*/ values.put(DirectMessages.CONVERSATION_ID, sender.getId()); } final String text_html = TwitterContentUtils.formatDirectMessageText(message); values.put(DirectMessages.TEXT_HTML, text_html); values.put(DirectMessages.TEXT_PLAIN, message.getText()); values.put(DirectMessages.TEXT_UNESCAPED, toPlainText(text_html)); values.put(DirectMessages.IS_OUTGOING, isOutgoing); values.put(DirectMessages.SENDER_NAME, sender.getName()); values.put(DirectMessages.SENDER_SCREEN_NAME, sender.getScreenName()); values.put(DirectMessages.RECIPIENT_NAME, recipient.getName()); values.put(DirectMessages.RECIPIENT_SCREEN_NAME, recipient.getScreenName()); values.put(DirectMessages.SENDER_PROFILE_IMAGE_URL, sender_profile_image_url); values.put(DirectMessages.RECIPIENT_PROFILE_IMAGE_URL, recipient_profile_image_url); final ParcelableMedia[] mediaArray = ParcelableMedia.fromEntities(message); if (mediaArray != null) { try { values.put(DirectMessages.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(mediaArray), ParcelableMedia.class)); } catch (IOException ignored) { } } return values; }
From source file:org.mariotaku.twidere.util.ContentValuesCreator.java
License:Open Source License
@NonNull public static ContentValues createStatus(final Status orig, final long accountId) { if (orig == null) throw new NullPointerException(); final ContentValues values = new ContentValues(); values.put(Statuses.ACCOUNT_ID, accountId); values.put(Statuses.STATUS_ID, orig.getId()); values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime()); final Status status; if (orig.isRetweet()) { final Status retweetedStatus = orig.getRetweetedStatus(); final User retweetUser = orig.getUser(); final long retweetedById = retweetUser.getId(); values.put(Statuses.RETWEET_ID, retweetedStatus.getId()); values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime()); values.put(Statuses.RETWEETED_BY_USER_ID, retweetedById); values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName()); values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName()); values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE, (retweetUser.getProfileImageUrlHttps())); values.put(Statuses.IS_RETWEET, true); if (retweetedById == accountId) { values.put(Statuses.MY_RETWEET_ID, orig.getId()); } else {/*w w w. j a v a 2 s . c om*/ values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); } status = retweetedStatus; } else if (orig.isQuote()) { final Status quotedStatus = orig.getQuotedStatus(); final User quoteUser = orig.getUser(); final long quotedById = quoteUser.getId(); values.put(Statuses.QUOTE_ID, quotedStatus.getId()); final String textHtml = TwitterContentUtils.formatStatusText(orig); values.put(Statuses.QUOTE_TEXT_HTML, textHtml); values.put(Statuses.QUOTE_TEXT_PLAIN, orig.getText()); values.put(Statuses.QUOTE_TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.QUOTE_TIMESTAMP, orig.getCreatedAt().getTime()); values.put(Statuses.QUOTE_SOURCE, orig.getSource()); final ParcelableMedia[] quoteMedia = ParcelableMedia.fromStatus(orig); if (quoteMedia != null && quoteMedia.length > 0) { try { values.put(Statuses.QUOTE_MEDIA_JSON, LoganSquare.serialize(Arrays.asList(quoteMedia), ParcelableMedia.class)); } catch (IOException ignored) { } } values.put(Statuses.QUOTED_BY_USER_ID, quotedById); values.put(Statuses.QUOTED_BY_USER_NAME, quoteUser.getName()); values.put(Statuses.QUOTED_BY_USER_SCREEN_NAME, quoteUser.getScreenName()); values.put(Statuses.QUOTED_BY_USER_PROFILE_IMAGE, quoteUser.getProfileImageUrlHttps()); values.put(Statuses.QUOTED_BY_USER_IS_VERIFIED, quoteUser.isVerified()); values.put(Statuses.QUOTED_BY_USER_IS_PROTECTED, quoteUser.isProtected()); values.put(Statuses.IS_QUOTE, true); status = quotedStatus; } else { values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet()); status = orig; } if (orig.isRetweet()) { values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(status)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName()); } else { values.put(Statuses.IN_REPLY_TO_STATUS_ID, orig.getInReplyToStatusId()); values.put(Statuses.IN_REPLY_TO_USER_ID, orig.getInReplyToUserId()); values.put(Statuses.IN_REPLY_TO_USER_NAME, TwitterContentUtils.getInReplyToName(orig)); values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, orig.getInReplyToScreenName()); } final User user = status.getUser(); final long userId = user.getId(); final String profileImageUrl = (user.getProfileImageUrlHttps()); final String name = user.getName(), screenName = user.getScreenName(); values.put(Statuses.USER_ID, userId); values.put(Statuses.USER_NAME, name); values.put(Statuses.USER_SCREEN_NAME, screenName); values.put(Statuses.IS_PROTECTED, user.isProtected()); values.put(Statuses.IS_VERIFIED, user.isVerified()); values.put(Statuses.USER_PROFILE_IMAGE_URL, profileImageUrl); values.put(CachedUsers.IS_FOLLOWING, user.isFollowing()); final String textHtml = TwitterContentUtils.formatStatusText(status); values.put(Statuses.TEXT_HTML, textHtml); values.put(Statuses.TEXT_PLAIN, status.getText()); values.put(Statuses.TEXT_UNESCAPED, toPlainText(textHtml)); values.put(Statuses.RETWEET_COUNT, status.getRetweetCount()); values.put(Statuses.REPLY_COUNT, status.getReplyCount()); values.put(Statuses.FAVORITE_COUNT, status.getFavoriteCount()); values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount()); values.put(Statuses.SOURCE, status.getSource()); values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive()); final GeoLocation location = status.getGeoLocation(); if (location != null) { values.put(Statuses.LOCATION, ParcelableLocation.toString(location.getLatitude(), location.getLongitude())); } final Place place = status.getPlace(); if (place != null) { values.put(Statuses.PLACE_FULL_NAME, place.getFullName()); } values.put(Statuses.IS_FAVORITE, status.isFavorited()); final ParcelableMedia[] media = ParcelableMedia.fromStatus(status); if (media != null && media.length > 0) { try { values.put(Statuses.MEDIA_JSON, LoganSquare.serialize(Arrays.asList(media), ParcelableMedia.class)); } catch (IOException ignored) { } } final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status); if (mentions != null && mentions.length > 0) { try { values.put(Statuses.MENTIONS_JSON, LoganSquare.serialize(Arrays.asList(mentions), ParcelableUserMention.class)); } catch (IOException ignored) { } } final ParcelableCardEntity card = ParcelableCardEntity.fromCardEntity(status.getCard(), accountId); if (card != null) { try { values.put(Statuses.CARD, LoganSquare.serialize(card)); values.put(Statuses.CARD_NAME, card.name); } catch (IOException ignored) { } } return values; }
From source file:org.mariotaku.twidere.util.UserColorNameManager.java
License:Open Source License
@Deprecated public String getDisplayName(final User user, final boolean nameFirst, final boolean ignoreCache) { return getDisplayName(user.getId(), user.getName(), user.getScreenName(), nameFirst, ignoreCache); }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
private void addFollower(User twitterUser, boolean createNewUsers) { if (twitterUser == null) { return;// w w w. ja v a2 s . c o m } int followersMax = 1000; int followersCount = twitterUser.getFollowersCount(); if (followersCount > followersMax) { // ignore users with to much followers log("Ignoring the " + followersCount + " Followers of " + twitterUser.getName()); return; } IDs followers; long cursor = -1; do { try { followers = twitterAPI.getFollowersIDs(twitterUser.getId(), cursor); log("Retrieving followers with cursor: " + cursor, LogService.LOG_INFO); } catch (TwitterException e) { log("Could not get more followers from twitter. (Cursor: " + cursor + "): " + e.getMessage(), LogService.LOG_DEBUG); break; } if (followers == null) { return; } // look up person for twitter user and connect Person connectToPerson = getPersonForTwitterUser(twitterUser); if (connectToPerson != null) { connectPersonsForTwitterUserIds(followers.getIDs(), connectToPerson, false, createNewUsers); } // next cursor cursor = followers.getNextCursor(); } while (followers.hasNext()); }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Looks up the person for this twitter user in the given dataSet and * returns it. If it does not already exist, the person will be created and * returned./*from www . ja va 2 s. c om*/ * * @param user * @return */ private Person createPersonFromTwitterUser(User user) { if (user == null) { return null; } Person person = getPersonForTwitterUser(user); String personIdent = createPersonIdentForTwitterUser(user); if (person == null) { // not previously created person = factory.createPerson(); // set name person.setName(user.getName()); // and add the person to the data set person = (Person) this.add(person, personIdent); } if (person == null) { // person could not be created return null; } // tag person person.metaTag(TwitterTags.TWITTER); // add web account String screenName = user.getScreenName(); if (screenName != null && !screenName.equals("")) { // TODO check for existing web account WebAccount webAccount = factory.createWebAccount(); webAccount.setUsername(screenName); webAccount.setCreated(user.getCreatedAt()); webAccount = (WebAccount) this.add(webAccount, screenName); if (webAccount != null) { webAccount.metaTag(TwitterTags.TWITTER); person.extend(webAccount); } } // add location String twitterLocation = user.getLocation(); if (twitterLocation != null && !twitterLocation.equals("")) { Location location = factory.createLocation(); location.setStringValue(twitterLocation); location = (Location) this.add(location, "uloc_" + user.getId()); if (location != null) { location.metaTag(TwitterTags.TWITTER); person.extend(location); } } // add website String twitterWebsite = user.getURL(); if (twitterWebsite != null) { WebSite website = factory.createWebSite(); website.setAdress(twitterWebsite.toString()); website = (WebSite) this.add(website); if (website != null) { website.metaTag(TwitterTags.TWITTER); person.extend(website); } } // add profile image String profileImageUrl = user.getBiggerProfileImageURL(); // add original res version if available if (screenName != null && source.isPropertyTrueElseDefault(TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_PROPERTY, TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_DEFAULT)) { if (user.getOriginalProfileImageURL() != null) { profileImageUrl = user.getOriginalProfileImageURL(); } } if (profileImageUrl != null) { // create image Image profileImage = person.attachImage(profileImageUrl); profileImage.tag(TwitterTags.TWITTER); profileImage.tag(TwitterTags.PROFILE_IMAGE); } // add latest status of user Status status = user.getStatus(); if (status != null && source.isPropertyTrue(TwitterProperties.ADD_STATUS_OF_PEOPLE_PROPERTY)) { createContentFromTweet(person, status); } return person; }