diff options
author | Vitaly Takmazov | 2016-11-28 14:37:02 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2016-11-28 14:37:02 +0300 |
commit | 5b2bd7f928bbf9d3233ff029ed5c09ac46daf0de (patch) | |
tree | cfad7f15e35c51d11a488df5a9b2be5300b9af54 /juick-www/src/main/java/com/juick/www/TwitterAuth.java | |
parent | c252087c54e91e63f89775eba4c65cf87ae21e5d (diff) |
all components using jackson now, org.json serializer moved to compatibility tests package
Diffstat (limited to 'juick-www/src/main/java/com/juick/www/TwitterAuth.java')
-rw-r--r-- | juick-www/src/main/java/com/juick/www/TwitterAuth.java | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/juick-www/src/main/java/com/juick/www/TwitterAuth.java b/juick-www/src/main/java/com/juick/www/TwitterAuth.java index 5ea58eb3..c6aaf9a1 100644 --- a/juick-www/src/main/java/com/juick/www/TwitterAuth.java +++ b/juick-www/src/main/java/com/juick/www/TwitterAuth.java @@ -1,5 +1,6 @@ package com.juick.www; +import com.fasterxml.jackson.databind.ObjectMapper; import com.github.scribejava.apis.TwitterApi; import com.github.scribejava.core.builder.ServiceBuilder; import com.github.scribejava.core.model.OAuth1AccessToken; @@ -8,7 +9,6 @@ import com.github.scribejava.core.model.OAuthRequest; import com.github.scribejava.core.model.Verb; import com.github.scribejava.core.oauth.OAuth10aService; import com.juick.server.UserQueries; -import org.json.JSONObject; import org.springframework.jdbc.core.JdbcTemplate; import javax.servlet.ServletException; @@ -26,9 +26,12 @@ public class TwitterAuth { private String consumerKey, consumerSecret; + private final ObjectMapper mapper; + public TwitterAuth(String consumerKey, String consumerSecret) { this.consumerKey = consumerKey; this.consumerSecret = consumerSecret; + mapper = new ObjectMapper(); } protected void doGet(JdbcTemplate sql, HttpServletRequest request, HttpServletResponse response) @@ -72,10 +75,9 @@ public class TwitterAuth { OAuth1AccessToken accessToken = oAuthService.getAccessToken(requestToken, verifier); OAuthRequest oAuthRequest = new OAuthRequest(Verb.GET, VERIFY_URL, oAuthService); oAuthService.signRequest(accessToken, oAuthRequest); - JSONObject jsonResponse = new JSONObject(oAuthRequest.send().getBody()); - String screenName = jsonResponse.getString("screen_name"); + com.juick.www.twitter.User twitterUser = mapper.readValue(oAuthRequest.send().getBody(), com.juick.www.twitter.User.class); if (UserQueries.linkTwitterAccount(sql, user, accessToken.getToken(), accessToken.getTokenSecret(), - screenName)) { + twitterUser.getScreenName())) { response.setStatus(HttpServletResponse.SC_FOUND); response.setHeader("Location", "http://juick.com/settings"); } else { |