Implementing Sign in with Twitter

I am trying to implement Twitter sign in in my java web application.

I am following this manual.

  1. I registered my application at here.
  2. But when i am trying to get request_token i am getting Response Code : 401.
    I am using following code to get request_token.

    String userUrl = “https://api.twitter.com/oauth/request_token“;

    String urlParam = oauth_callback + “&” + oauth_consumer_key + “&” + oauth_nonce + “&”+ oauth_signature + “&” + oauth_signature_method+”&”+oauth_timestamp+”&”+oauth_version;

    URL url = new URL(userUrl);
    HttpURLConnection con = (HttpURLConnection) url.openConnection();
    con.setRequestMethod(“POST”);

    con.setRequestProperty(“Accept-Language”, “en-US,en;q=0.5”);
    String urlParameters = urlParam;
    con.setDoOutput(true);

    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(urlParameters);
    wr.flush();
    wr.close();
    int responseCode = con.getResponseCode();


Source: java

Leave a Reply