REST API https://api.twitter.com/1.1/statuses/user_timeline.json gives Http Response code 401


#1

Hi
@episod

Actual URL :- https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=userid&count=2
oauth_nonce = 2e31769a7a984208b91f380c6c251a92 which i generated randomly
oauth_timestamp=generated using following
Calendar tempcal = Calendar.getInstance();
long ts = tempcal.getTimeInMillis();// get current time in milliseconds
String oauth_timestamp = (new Long(ts/1000)).toString(); // oauth_timestamp generated

oauth_timestamp=1371209304

signature BaseString: GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fuser_timeline.json&count%3D2%26oauth_consumer_key%3DnoktasToxIMzLnaqnEpGEQ%26oauth_nonce%3D2e31769a7a984208b91f380c6c251a92%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1371209304%26oauth_token%3Duserid-fv4jsl1cVWxdpB1m8QvvNWLqUHDZeJEUzqKsz9N4%26oauth_version%3D1.0%26user_id%3DGIVENUSERID

sending the signature base string to the HMAC SHA1 algorithm got the result as

oauth_signature=6A9YWN60Hc9r6HLZUukkIGfXbCA%3D

below is the code i am sending
{
httpConn = (HttpURLConnection) url.openConnection();
httpConn.setUseCaches(false);

    String consumerKey = "noktasToxIMzLnaqnEpGEQ";
    String authorization_header_string = "OAuth oauth_consumer_key=\""+ consumerKey+ "\",oauth_nonce=\"" + oauth_nonce+ "\",oauth_signature=\""+ oauth_signature + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" +oauth_timestamp + "\",oauth_token=\"userid-fv4jsl1cVWxdpB1m8QvvNWLqUHDZeJEUzqKsz9N4\",oauth_version=\"1.0\"";
    httpConn.setRequestProperty("Authorization",authorization_header_string);
    
    httpConn.setDoInput(true); // true if we want to read server's response
    httpConn.setDoOutput(false); // false indicates this is a GET request

}

Gives following exception
Server returned HTTP response code: 401 for URL: https://api.twitter.com/1.1/statuses/user_timeline.json?user_id=userid&count=2

(Note:- USER_ID what i got is not showing here , i replace here with “userid”)

Sending this URL with the
Authorization header