Пример #1
0
 public boolean createTumblrUser(String oauth_token, String oauth_verifier)
     throws RemoteException, SQLException {
   Verifier verifier = new Verifier(oauth_verifier);
   Token accessToken = RMIServer.service.getAccessToken(RMIServer.request_token, verifier);
   String user_token = accessToken.getToken();
   String user_secret = accessToken.getSecret();
   Token newToken = new Token(user_token, user_secret);
   OAuthRequest request = new OAuthRequest(Verb.GET, "https://api.tumblr.com/v2/user/info");
   request.addHeader("Accept", "application/json");
   RMIServer.service.signRequest(newToken, request);
   System.out.println(request.getHeaders().keySet());
   org.scribe.model.Response response = request.send();
   JSONObject jsonresponse = new JSONObject(response.getBody());
   String name = jsonresponse.getJSONObject("response").getJSONObject("user").getString("name");
   ResultSet resultSet =
       connection
           .createStatement()
           .executeQuery("select * from users where username = \"" + name + "\"");
   if (resultSet.next()) {
     connection
         .createStatement()
         .execute(
             "update users set userToken = \""
                 + user_token
                 + "\" , userSecret = \""
                 + user_secret
                 + "\" where username = \""
                 + name
                 + "\"");
   } else {
     connection
         .createStatement()
         .execute(
             "insert into users (username,password, balance , userToken, userSecret) values (\""
                 + name
                 + "\","
                 + "\"tumblr\","
                 + 100
                 + ", "
                 + "\""
                 + user_token
                 + "\", "
                 + "\""
                 + user_secret
                 + "\")");
   }
   return true;
 }
 private String extractAuthenticationHeader(final OAuthRequest request) {
   final Map<String, String> headers = request.getHeaders();
   return Objects.requireNonNull(headers.get("Authorization"));
 }