List of usage examples for twitter4j Twitter getOAuthAccessToken
AccessToken getOAuthAccessToken(RequestToken requestToken, String oauthVerifier) throws TwitterException;
From source file:uk.trainwatch.web.auth.twitter.TwitterCallbackServlet.java
@Override protected void doSecureGet(ApplicationRequest request) throws ServletException, IOException { HttpSession session = request.getRequest().getSession(); Twitter twitter = (Twitter) session.getAttribute("twitter"); RequestToken requestToken = (RequestToken) session.getAttribute("requestToken"); String verifier = request.getParam().get("oauth_verifier"); try {//from w w w . ja v a 2 s . c o m if (twitter == null || requestToken == null || verifier == null) { request.redirect("/", true); } else { twitter.getOAuthAccessToken(requestToken, verifier); User user = null; if (request.isAuthenticated()) { // Link to existing user user = userFactory.linkTwitter(request.getUser(), twitter); } else { // Login/Register new user user = userFactory.loginOrRegisterTwitter(twitter); } if (user != null) { session.setAttribute(User.KEY, user); } request.redirect("/home", true); } } catch (SQLException | TwitterException ex) { throw new ServletException(ex); } finally { session.removeAttribute("twitter"); session.removeAttribute("requestToken"); } }