i have some difficulty which confused me for a long time.I was trapped in the first step --INIT. it always return 401. i know it means no authorization! But it has been authorized.i can even post a tweet and image.i think that signature may be wrong.and what is the meaning of this sentence :
Because the method uses multipart POST, OAuth is handled differently. POST or query string parameters are not used when calculating an OAuth signature basestring or signature. Only the oauth_* parameters are used.
thanks for everyone help me.i am looking forward to your reply
this is my code:
String parameter_string = "oauth_consumer_key=" + oauth_consumer_key + "&oauth_nonce=" + oauth_nonce + "&oauth_signature_method=" + oauth_signature_method + "&oauth_timestamp="
+ oauth_timestamp + "&oauth_token=" + URLEncoder.encode(oauth_token, "UTF-8") + "&oauth_version=1.0&status=" + URLEncoder.encode(tweet, "UTF-8");
String signature_base_string = "POST&" + URLEncoder.encode(ysTwitter.getUpdateStatusUrl(), "UTF-8") + "&" + URLEncoder.encode(parameter_string, "UTF-8");
String oauth_signature = "";
oauth_signature = ysTwitter.computeSignature(signature_base_string, oauth_consumer_secret + "&" + URLEncoder.encode(oauth_token_secret, "UTF-8"));
String authorization_header_string = "OAuth oauth_consumer_key=\"" + oauth_consumer_key + "\",oauth_signature_method=\"HMAC-SHA1\",oauth_timestamp=\"" + oauth_timestamp
+ "\",oauth_nonce=\"" + oauth_nonce + "\",oauth_version=\"1.0\",oauth_signature=\"" + URLEncoder.encode(oauth_signature, "UTF-8") + "\",oauth_token=\""
+ URLEncoder.encode(oauth_token, "UTF-8") + "\"";
URL url = new URL(ysTwitter.getUpdateStatusUrl());
// HttpURLConnection connection = (HttpURLConnection)
// url.openConnection(proxy);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setRequestProperty("Connection", "Keep-Alive");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");
connection.setRequestProperty("Authorization", authorization_header_string);
connection.setConnectTimeout(50000);
connection.setReadTimeout(30000);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.connect();