[twitter-dev] Re: OAuth authentication issuse

2010-08-17 Thread LINUXGEEK
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();
  

Re: [twitter-dev] Re: OAuth authentication issuse

2010-08-17 Thread Tom van der Woerdt
Hi,

According to the guide How To Ask Questions The Smart Way
http://catb.org/esr/faqs/smart-questions.html#asking, it is unwise to
flag your question as urgent. ;-)

Anyway, to answer your question: That's a lot of code, but I prefer to
know what it is doing over the actual code. So: can you post a request
which you make to Twitter, and can you give the Base String which you
use for generating the signature?

Tom


On 8/17/10 1:58 PM, LINUXGEEK wrote:
 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) {