0

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(); 
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
sumit kumar
  • 602
  • 3
  • 11
  • 26

1 Answers1

0

As the doc suggests, you have to put these "urlparams" in the headers, not in the URL parameters : https://dev.twitter.com/oauth/reference/post/oauth/request_token

You might also find this useful: Implement OAuth in Java

Community
  • 1
  • 1
Jérémy
  • 108
  • 8
  • Can you help me how to do that – sumit kumar May 22 '15 at 09:21
  • The link I provided contains a complete, clear and commented code, I think it will help you more than what I could say in a few comments :) – Jérémy May 22 '15 at 09:33
  • That is too vague. However, 403 means you should be authenticated to perform the action. Also, do not hesitate to upvote my post in case you found it useful :) – Jérémy May 22 '15 at 10:56