hey am getting the same error like "UnAuthorized" here is my code.. if anything wrong plz replay its urgent
private void StatusUpdate() throws CryptoTokenException, CryptoUnsupportedOperationException, IOException { String oauth_signature_method = "HMAC-SHA1"; String oauth_timestamp = String.valueOf(timestamp()); String oauth_nonce = createNonce(oauth_timestamp); String oauth_version = "1.0"; String postBody = "status=" + URLUTF8Encoder.encode("Finally i got success"); String baseString = "POST&" + URLUTF8Encoder .encode("https://twitter.com/statuses/update.json") + "&oauth_consumer_key%3D" + "my consumer Secret" + "%26oauth_nonce%3D" + oauth_nonce + "%26oauth_signature_method%3D" + oauth_signature_method + "%26oauth_token%3D" + token.getToken() + "%26oauth_timestamp%3D" + oauth_timestamp + "%26oauth_version%3D" + oauth_version + "%26" + URLUTF8Encoder.encode(postBody); String signingSecret = URLUTF8Encoder .encode("RU49YpOoPLaIfasdfasdf53245fsdfssdfas") + "&" + URLUTF8Encoder.encode(token.getSecret()); String signature = hmacsha1(signingSecret, baseString); Dialog.alert(signature); String header = new StringBuffer("OAuth oauth_nonce=\"").append( URLUTF8Encoder.encode(oauth_nonce)).append( "\", oauth_signature_method=\"").append( URLUTF8Encoder.encode(oauth_signature_method)).append( "\", oauth_timestamp=\"").append( URLUTF8Encoder.encode(oauth_timestamp)).append( "\", oauth_consumer_key=\"").append("my consumer Secret") .append("\",oauth_token=\"").append( URLUTF8Encoder.encode(token.getToken())).append( "\", oauth_signature=\"").append( URLUTF8Encoder.encode(signature)).append( "\", oauth_version=\"").append(oauth_version).append( "\"").toString(); UpdateMyNewStatus(header, postBody); } public static void UpdateMyNewStatus(String auth_header, String body) { String url = "https://twitter.com/statuses/update.json"; HttpConnection httpConn = null; InputStream input = null; OutputStream os = null; try { httpConn = (HttpConnection) Connector.open(url + ConnectionUtils.getConnectionPerameter()); httpConn.setRequestMethod(HttpConnection.POST); httpConn.setRequestProperty("WWW-Authenticate", "OAuth realm=http://twitter.com/"); httpConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); String authHeader = auth_header; httpConn.setRequestProperty("Authorization", authHeader); // write post body String postBody = body; httpConn.setRequestProperty("Content-Length", Integer .toString(postBody.getBytes().length)); os = httpConn.openOutputStream(); os.write(postBody.getBytes()); os.close(); os = null; input = httpConn.openInputStream(); int resp = httpConn.getResponseCode(); Dialog.alert(httpConn.getResponseMessage()); if (resp == HttpConnection.HTTP_OK) { StringBuffer buffer = new StringBuffer(); int ch; while ((ch = input.read()) != -1) { buffer.append((char) ch); } String content = buffer.toString(); Dialog.alert(content); } } catch (Exception e) { } finally { try { httpConn.close(); input.close(); } catch (IOException e) { e.printStackTrace(); } } } On Aug 16, 10:13 pm, Tom van der Woerdt <i...@tvdw.eu> wrote: > On 8/16/10 6:41 PM, Jims wrote: > > > > > Hi guys, > > > request":"/1/statuses/update.json","error":"Could not authenticate > > you. > > > I am trying to post a tweet to one of my accounts using oAuth, with a > > script I wrote on PERL. I'm sending the request as a POST with the > > required tokens in the header. but I keep getting this error > > > request":"/1/statuses/update.json","error":"Could not authenticate > > you. > > > Additional info: > > > I have the consumer key and secret, oauth token and secret, I'm > > generating the nonce myself, I'm passing a timestamp in milliseconds . > > > I believe I am constructing the signature in the correct order, and am > > using the consumer and oauth secrets to sign them. > > > Everything is url encoded. > > > Is there something I have to do before I can tweet, bearing in mind I > > have all the tokens > > Hi, > > The error you get is the error people get when not sending the oauth > information like signature, token, etc. You should send the OAuth > information in the Authorization: header. > > Also, you should pass the timestamp in seconds since the unix epoch, not > in milliseconds. > > If this does not solve it, please show me one of your Base Strings. > > Tom