List of usage examples for twitter4j Twitter showUser
User showUser(long userId) throws TwitterException;
From source file:it.greenvulcano.gvesb.social.twitter.directcall.TwitterOperationGetUserTimeline.java
License:Open Source License
@Override public void execute(SocialAdapterAccount account) throws SocialAdapterException { try {/*from www. j ava 2 s . c o m*/ Twitter twitter = (Twitter) account.getProxyObject(); Paging paging = new Paging(); if ((sinceId != null) && !"".equals(sinceId)) { paging.setSinceId(Long.parseLong(sinceId)); } if ((maxId != null) && !"".equals(maxId)) { paging.setMaxId(Long.parseLong(maxId)); } if ((count != null) && !"".equals(count)) { paging.setCount(Integer.parseInt(count)); } if ((userId == null) || "".equals(userId)) { dataUser = twitter.getScreenName(); dataUserId = String.valueOf(twitter.getId()); statusList = twitter.getUserTimeline(paging); } else { User user = null; try { long id = Long.parseLong(userId); user = twitter.showUser(id); statusList = twitter.getUserTimeline(id, paging); } catch (NumberFormatException exc) { user = twitter.showUser(userId); statusList = twitter.getUserTimeline(userId, paging); } dataUser = user.getScreenName(); dataUserId = String.valueOf(user.getId()); } } catch (NumberFormatException exc) { logger.error("Call to TwitterOperationGetUserTimeline failed. Check userId[" + userId + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] format.", exc); throw new SocialAdapterException("Call to TwitterOperationGetUserTimeline failed. Check followingId[" + userId + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] format.", exc); } catch (TwitterException exc) { logger.error("Call to TwitterOperationGetUserTimeline followingId[" + userId + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] failed.", exc); throw new SocialAdapterException("Call to TwitterOperationGetUserTimeline followingId[" + userId + "], sinceId[" + sinceId + "], maxId[" + maxId + "] and count[" + count + "] failed.", exc); } }
From source file:jp.gr.java_conf.ya.shiobeforandroid3.UpdateTweetMultiple.java
License:Open Source License
private final String init_user_oauth(final int index) { oauthToken = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_" + index, "")); if (oauthToken.equals("")) { WriteLog.write(this, "oauthToken.equals(\"\")"); final SharedPreferences.Editor editor = pref_twtr.edit(); editor.putString("index", "0"); editor.remove("consumer_key_" + index); editor.remove("consumer_secret_" + index); editor.remove("oauth_token_" + index); editor.remove("oauth_token_secret_" + index); editor.remove("profile_image_url_" + index); editor.remove("screen_name_" + index); editor.remove("status_" + index); editor.commit();//from w ww .java 2 s.c o m } consumerKey = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_key_" + index, "")); consumerSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("consumer_secret_" + index, "")); if (consumerKey.equals("") || consumerSecret.equals("")) { WriteLog.write(this, "(consumerKey.equals(\"\") || consumerSecret.equals(\"\"))"); consumerKey = getString(R.string.default_consumerKey); consumerSecret = getString(R.string.default_consumerSecret); } pref_app = PreferenceManager.getDefaultSharedPreferences(this); pref_timeout_t4j_connection = ListAdapter.getPrefInt(this, "pref_timeout_t4j_connection", "20000"); pref_timeout_t4j_read = ListAdapter.getPrefInt(this, "pref_timeout_t4j_read", "120000"); oauthTokenSecret = MyCrypt.decrypt(this, crpKey, pref_twtr.getString("oauth_token_secret_" + index, "")); try { confbuilder = new ConfigurationBuilder(); } catch (final IllegalStateException e) { WriteLog.write(this, e); } catch (final Exception e) { WriteLog.write(this, e); } confbuilder.setOAuthAccessToken(oauthToken).setOAuthAccessTokenSecret(oauthTokenSecret) .setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setHttpConnectionTimeout(pref_timeout_t4j_connection).setHttpReadTimeout(pref_timeout_t4j_read) .setHttpRetryCount(3).setHttpRetryIntervalSeconds(10);// .setUseSSL(true); Twitter twtr; try { conf = confbuilder.build(); twtr = new TwitterFactory(conf).getInstance(); } catch (final Exception e) { twtr = null; WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } WriteLog.write(this, "init_user_oauth(): conf: " + conf.toString()); WriteLog.write(this, "init_user_oauth(): twtr: " + twtr.toString()); if (twtr != null) { try { screenName = twtr.getScreenName(); User user = twtr.showUser(screenName); final String profile_image_url = user.getProfileImageURL().toString(); pref_twtr = getSharedPreferences("Twitter_setting", MODE_PRIVATE); final SharedPreferences.Editor editor = pref_twtr.edit(); editor.putString("screen_name_" + index, screenName); editor.putString("profile_image_url_" + index, profile_image_url); editor.commit(); WriteLog.write(this, "screenName: " + screenName); WriteLog.write(this, "profile_image_url: " + profile_image_url); } catch (final TwitterException e) { WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } catch (final Exception e) { WriteLog.write(this, e); adapter.toast(getString(R.string.cannot_access_twitter) + System.getProperty("line.separator") + getString(R.string.tryagain_oauth)); } } return screenName; }
From source file:kerguelenpetrel.BotherSomeoneServlet.java
License:Apache License
@Override public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { StringBuilder builder = new StringBuilder(); long[] friendIDs, victimIDs; resp.setContentType("text/plain; charset=UTF-8"); try {/*from ww w . j a va 2s.co m*/ //Get the Twitter object Twitter twit = TwitterFactory.getSingleton(); //Find a friend of a follower to bother friendIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs(); if (friendIDs.length == 0) { resp.getWriter().println("Cannot find any followers to bother \n"); return; } //Load the potential victim IDs victimIDs = twit.getFollowersIDs(friendIDs[r.nextInt(friendIDs.length)], cursor).getIDs(); if (victimIDs.length == 0) { resp.getWriter().println("Cannot find any followers to bother \n"); return; } //Write to our victim String victim = twit.showUser(victimIDs[r.nextInt(victimIDs.length)]).getScreenName(); //Get a global trend Trends t = twit.getPlaceTrends(1); String trend = t.getTrends()[r.nextInt(t.getTrends().length)].getName(); builder.append(getWordnikContent(victim, trend, resp)); if (builder.length() > 280) builder.setLength(280); //Tweets are limited to 280 characters //Set the status StatusUpdate status = new StatusUpdate(builder.toString()); //Post the status twit.updateStatus(status); resp.getWriter().println("Tweet posted: " + status.getStatus()); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter \n"); e.printStackTrace(resp.getWriter()); } }
From source file:kerguelenpetrel.FriendSomeoneServlet.java
License:Apache License
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { User friend = null;//from w w w .j a v a 2 s . co m resp.setContentType("text/plain; charset=UTF-8"); try { //Get the Twitter object Twitter twit = TwitterFactory.getSingleton(); //Find a friend of a follower to bother long[] followerIDs = twit.getFollowersIDs(twit.getId(), cursor, 30).getIDs(); if (followerIDs.length == 0) { resp.getWriter().println("Cannot find any followers \n"); return; } //Load the potential victim IDs long[] friendIDs = twit.getFollowersIDs(followerIDs[r.nextInt(followerIDs.length)], cursor).getIDs(); if (friendIDs.length == 0) { resp.getWriter().println("Cannot find any followers to bother \n"); return; } //Get a new friend friend = twit.showUser(friendIDs[r.nextInt(friendIDs.length)]); twit.createFriendship(friend.getId()); resp.getWriter().println("Made a new friend with @" + friend.getScreenName()); //Write to our new friend StatusUpdate status = new StatusUpdate(writeToFriend(friend.getScreenName(), resp)); twit.updateStatus(status); resp.getWriter().println("Tweet posted: " + status.getStatus()); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter \n"); e.printStackTrace(resp.getWriter()); } }
From source file:kerguelenpetrel.UnfriendSomeoneServlet.java
License:Apache License
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { User unfriend = null;//from w w w.j a va 2s. co m Random r = new Random(); resp.setContentType("text/plain; charset=UTF-8"); try { //Get the Twitter object Twitter twit = TwitterFactory.getSingleton(); //Find a friend of a follower to bother long[] followerIDs = twit.getFollowersIDs(twit.getId(), cursor).getIDs(); if (followerIDs.length == 0) { resp.getWriter().println("No friends to unfollow"); return; } unfriend = twit.showUser(followerIDs[r.nextInt(followerIDs.length)]); twit.destroyFriendship(unfriend.getId()); resp.getWriter().println("Successfully unfollowed @" + unfriend.getScreenName()); resp.getWriter().println("\n"); } catch (TwitterException e) { resp.getWriter().println("Problem with Twitter \n"); e.printStackTrace(resp.getWriter()); } catch (Exception e) { resp.getWriter().println("Problem! \n"); e.printStackTrace(resp.getWriter()); } }
From source file:net.firejack.platform.web.security.twitter.BaseTwitterAuthenticationProcessor.java
License:Apache License
protected Map<String, String> getTwitterUserInformation(Twitter twitterService) throws TwitterException { Map<String, String> userInfo = new HashMap<String, String>(); long id = twitterService.getId(); userInfo.put(TW_USER_ID, String.valueOf(id)); String screenName = twitterService.getScreenName(); userInfo.put(TW_SCREEN_NAME, screenName); twitter4j.User user = twitterService.showUser(id); userInfo.put(TW_US_SCREEN_NAME, user.getScreenName()); userInfo.put(TW_US_NAME, user.getName()); userInfo.put(TW_US_PROFILE_IMAGE_URL, user.getProfileImageURL()); return userInfo; }
From source file:ontoSentiment.Amigos.java
@Override public void run() { ConfigurationBuilder cb = new ConfigurationBuilder(); //the following is set without accesstoken- desktop client cb.setDebugEnabled(true).setOAuthConsumerKey("FBd5n7dyl8mCz73qyfZ0p4XHb") .setOAuthConsumerSecret("vu5Xt5TzBSL9naOZylIYlx5MdcRlhH2LvkpW6KIkxSf9AqwuGt") .setOAuthAccessToken("3232400175-lAchtC6ChWMTnJKe3BaWbst8SucIaTjn5gm4Rp2") .setOAuthAccessTokenSecret("DnkquBWAS6igYpM8Z4r54hH7ztcfMX6u8OzMXBLwM9Xkh"); try {/*from ww w.ja va 2s . com*/ TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); //User u = twitter.showUser("karlaffabiola"); User u = twitter.showUser("raythemaster"); IDs ids; System.out.println("Listing followers's ids."); System.out.println("ID: " + u.getId()); System.out.println("Nome: " + u.getScreenName()); long cursor = -1; PagableResponseList<User> pagableFollowings; List<User> listFriends = new ArrayList<>(); List<User> listFriends2 = new ArrayList<>(); pagableFollowings = twitter.getFriendsList(u.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user : pagableFollowings) { System.out.println("Id: " + user.getId() + " Nome: " + user.getScreenName()); listFriends.add(user); // ArrayList<User> } for (User user : listFriends) { System.out.println("Id1: " + user.getId() + " Nome1: " + user.getScreenName()); pagableFollowings = twitter.getFriendsList(user.getId(), cursor, 200); System.out.println("Qunatidade followers: " + pagableFollowings.size()); for (User user2 : pagableFollowings) { System.out.println("Id2: " + user2.getId() + " Nome2: " + user2.getScreenName()); listFriends2.add(user2); // ArrayList<User> } } System.out.println("Lista 1:" + listFriends.size()); System.out.println("Lista 2:" + listFriends2.size()); System.exit(0); } catch (TwitterException te) { // te.printStackTrace(); System.out.println("Failed to get timeline: " + new Date()); try { Thread.sleep(3 * 60 * 1000); run(); } catch (InterruptedException ex) { Logger.getLogger(Amigos.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private ProfileDto getUserProfile(String username) { try {//from w w w. j av a 2 s.c om Twitter twitter = getTwitter(); User user = twitter.showUser(username); ProfileDto profileDto = new ProfileDto(); profileDto.setScreenName(user.getScreenName()); profileDto.setImageURL(user.getProfileImageURL().toString()); profileDto.setDescription(user.getDescription()); return profileDto; } catch (TwitterException te) { throw new RuntimeException(te); } }
From source file:org.getlantern.firetweet.util.TwitterWrapper.java
License:Open Source License
@NonNull public static User showUser(final Twitter twitter, final long id, final String screenName) throws TwitterException { if (twitter.getId() == id || twitter.getScreenName().equalsIgnoreCase(screenName)) { return twitter.verifyCredentials(); } else if (id != -1) { return twitter.showUser(id); } else if (screenName != null) { return twitter.showUser(screenName); }//from w ww. j ava 2 s. c o m throw new IllegalArgumentException(); }
From source file:org.kawalpemilukada.login.callbackTwit.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w w w. j a v a 2 s .co 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 { Twitter twitter = (Twitter) request.getSession().getAttribute("twitter"); RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken"); String verifier = request.getParameter("oauth_verifier"); String rurl = request.getParameter("rurl"); try { twitter.getOAuthAccessToken(requestToken, verifier); request.getSession().removeAttribute("requestToken"); } catch (TwitterException e) { } request.getSession().setAttribute("twitter", twitter); String errorMsg = "Data Anda belum terverifikasi."; Dashboard dashboard = CommonServices.getDashboard(CommonServices.setParentId("2015", "0")); Dashboard dashboard2014 = CommonServices.getDashboard(CommonServices.setParentId("2014", "0")); request.getSession().removeAttribute("tahun"); UserData user = null; try { User u = twitter.showUser(twitter.getId()); user = ofy().load().type(UserData.class).id("twit" + CommonServices.getVal(twitter.getId())).now(); if (user == null) { 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.type = "twit"; user.userlevel = 100; user.terverifikasi = "Y"; ofy().save().entity(user).now(); dashboard.users = CommonServices.getuserSize() + ""; ofy().save().entity(dashboard).now(); dashboard2014.users = dashboard.users + ""; ofy().save().entity(dashboard2014).now(); } else { user.lastlogin = CommonServices.JakartaTime(); user.type = "twit"; user.imgurl = u.getBiggerProfileImageURL().replace("http://", "https://"); if (user.type.equalsIgnoreCase("twit") && user.nama.equalsIgnoreCase(CommonServices.getVal(u.getName()))) { if (user.terverifikasi.equalsIgnoreCase("Y")) { errorMsg = ""; } } else { user.nama = CommonServices.getVal(u.getName()); user.terverifikasi = "N"; } ofy().save().entity(user).now(); } Gson gson = new Gson(); request.getSession().setAttribute("UserData", JSONValue.parse(gson.toJson(user))); } catch (Exception e) { errorMsg = "callbackTwit [processRequest] ==> " + e.toString(); } response.setContentType("text/html;charset=UTF-8"); Gson gson = new Gson(); try (PrintWriter out = response.getWriter()) { /* TODO output your page here. You may use following sample code. */ out.println("<!DOCTYPE html>"); out.println("<html>"); out.println("<head>"); out.println("<title>Kawal Pemilu Kepala Daerah</title>"); out.println("<script src=\"/bower_components/jquery/dist/jquery.min.js\"></script>"); out.println("<script src=\"/dist/js/vendor.js\"></script>"); out.println("</head>"); out.println("<body>Sedang Login..."); out.println("<script>"); out.println("if (!jQuery.browser.mobile) {"); out.println("try{window.opener.inviteCallback(" + gson.toJson(user) + "," + gson.toJson(dashboard) + ",'" + errorMsg + "');}catch(e){window.location='/'}"); out.println("self.close();"); out.println("}else{window.location='/#" + rurl + "'}"); out.println("</script>"); out.println("</body>"); out.println("</html>"); } }