List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory()
From source file:com.ikungolf.java.javatwitter.twitterCmd.java
public Status getLastestMessage() { String msg = new String(); Status s = null;/*from w w w .j a va2 s.c om*/ // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try { User user = twitter.verifyCredentials(); List<Status> statuses = twitter.getMentionsTimeline(); s = statuses.get(0); msg = s.getText(); System.out.println("Message: " + s.getText()); // for (Status status : statuses) { // System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); // } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } return s; }
From source file:com.ikungolf.java.javatwitter.twitterCmd.java
public void updateStatus(String msg) { if (msg == null) { System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); System.exit(-1);/*from w w w. j a v a 2s . co m*/ } try { Twitter twitter = new TwitterFactory().getInstance(); try { // get request token. // this will throw IllegalStateException if access token is already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { System.out.println("OAuth consumer key/secret is not set."); System.exit(-1); } } Status status = twitter.updateStatus(msg); System.out.println("Successfully updated the status to [" + status.getText() + "]."); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } }
From source file:com.itbs.aimcer.commune.twitter.TwitterConnection.java
License:Open Source License
public void connectReal() { try {//from www . ja va 2 s .c o m connection = new TwitterFactory().getInstance(); if (getUserName() != null && getUserName().length() > 0) { connection.setOAuthConsumer(getUserName(), getPassword()); } getList(); fireConnect(); } catch (Exception e) { // Lets see if we see this with Google. log.log(Level.SEVERE, "UNCAUGHT EXCEPTION! PLEASE FIX!", e); disconnect(false); notifyConnectionFailed("Connection Failed. UNUSUAL TERMINATION!" + e.getMessage()); } }
From source file:com.javielinux.twitter.ConnectionManager.java
License:Apache License
public String getAuthenticationURL() throws TwitterException { NetworkConfig config = getNetworkConfig(); twitterOAuth = new TwitterFactory().getInstance(); twitterOAuth.setOAuthConsumer(config.getConsumerKey(), config.getConsumerSecret()); requestTokenOAuth = twitterOAuth.getOAuthRequestToken();//AuthorizationActivity.TWITTER_HOST); Log.d(Utils.TAG, "Redirigiendo a " + requestTokenOAuth.getAuthorizationURL()); return requestTokenOAuth.getAuthorizationURL(); }
From source file:com.jeanchampemont.wtfdyum.utils.TwitterFactoryHolder.java
License:Apache License
public TwitterFactoryHolder() { twitterFactory = new TwitterFactory(); }
From source file:com.lorenzobraghetto.speakbird.Logic.TwitterService.java
License:Open Source License
protected boolean checkForSavedLogin() { // Get Access Token and persist it AccessToken a = getAccessToken();/*from w w w. j av a2 s.com*/ if (a == null) { return false; //if there are no credentials stored then return to usual activity } // initialize Twitter4J twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(a); ((SpeakBirdApplication) getApplication()).setTwitter(twitter); //startFirstActivity(); //finish(); return true; }
From source file:com.lorenzobraghetto.speakbird.View.Mentions.java
License:Open Source License
protected boolean checkForSavedLogin() { // Get Access Token and persist it AccessToken a = getAccessToken();/*w w w. ja va 2s. co m*/ if (a == null) { return false; //if there are no credentials stored then return to usual activity } // initialize Twitter4J twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(a); ((SpeakBirdApplication) getSherlockActivity().getApplication()).setTwitter(twitter); return true; }
From source file:com.marklogic.tweetdeck.SaveRawJSON.java
License:Apache License
/** * Usage: java twitter4j.examples.json.SaveRawJSON * * @param args/* w w w . j a v a 2 s. co m*/ * String[] */ public static void main(String[] args) { Twitter twitter = new TwitterFactory().getInstance(); System.out.println("Saving public timeline."); try { new File("statuses").mkdir(); List<Status> statuses = twitter.getHomeTimeline(); for (Status status : statuses) { String rawJSON = TwitterObjectFactory.getRawJSON(status); String fileName = "statuses/" + status.getId() + ".json"; storeJSON(rawJSON, fileName); System.out.println(fileName + " - " + status.getText()); } System.out.print("\ndone."); System.exit(0); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to store tweets: " + ioe.getMessage()); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
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 v a2 s .c om 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.metadot.book.connectr.server.servlets.LoginTwitterServlet.java
License:Apache License
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { Twitter twitter = new TwitterFactory().getInstance(); // get auth info from system properties String key = AuthenticationProvider.getProp("twitter-consumer-key"); String secret = AuthenticationProvider.getProp("twitter-consumer-secret"); if (key == null || secret == null) { response.setContentType("text/html"); response.getWriter().print(AppLib.INFONOTFOUND); return;/*from ww w .j a v a 2s . c o m*/ } try { twitter.setOAuthConsumer(key, secret); String callbackURL = buildCallBackURL(request, AuthenticationProvider.TWITTER); RequestToken token = twitter.getOAuthRequestToken(callbackURL); request.getSession().setAttribute("requestToken", token); String loginURL = token.getAuthenticationURL() + "&force_login=true"; log.info("Redirecting to: " + loginURL); response.sendRedirect(loginURL); } catch (TwitterException e) { response.setContentType("text/html"); response.getWriter().print("<p>" + e.getMessage() + "</p>"); response.getWriter().print(AppLib.INFONOTFOUND); return; // e.printStackTrace(); } }