[twitter-dev] Android OAUTH Incorrect Signature error

2010-10-25 Thread yogeshkolte
Well following code works when I make api call immediately after
authorization onNewIntent event but when I put same code in Adapter
class  I get incorrect signature error.  I am using CallbackURL. Do we
always need to create consume object using verifier or
setTokenWithSecret  should work on subsequent calls.  Any help is
appreciated

Thanks


if (1 == 1) // WORKS
{
String surl = 
"http://api.twitter.com/1/account/
verify_credentials.xml";

HttpGet request = null;
HttpClient httpClient = null;
HttpResponse response = null;
request = new HttpGet(surl);
httpOauthConsumer.sign(request);
System.out.println("Sending request to 
Twitter...");
httpClient = new DefaultHttpClient();

response = httpClient.execute(request);
String sresponse = 
parseResponseToString(response);
Log.d(TAG, sresponse);
} else {
 //  GET INCORRECT SIGNATURE
ERROR

TwitterAdapter adapter = new 
TwitterAdapter(null,
consumerKey, 
consumerSecret, userKey, userSecret);
String s = adapter.VerifyUser();
Log.d(TAG, s);
}

Here is full code

package com.sogeti.msl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import oauth.signpost.OAuthProvider;
import oauth.signpost.basic.DefaultOAuthProvider;
import oauth.signpost.commonshttp.CommonsHttpOAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

public class OAuthForTwitter extends Activity {
private static String TAG = "OAuthForTwitter";

private CommonsHttpOAuthConsumer httpOauthConsumer;
private OAuthProvider httpOauthprovider;
public final static String consumerKey = "";
public final static String consumerSecret = "";
private final String CALLBACKURL = "myapp://mainactivity";

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
doOauth();
}

private void doOauth() {
try {
httpOauthConsumer = new
CommonsHttpOAuthConsumer(consumerKey,consumerSecret);
httpOauthprovider = new 
DefaultOAuthProvider("http://twitter.com/
oauth/request_token",
"http://twitter.com/oauth/access_token";,
"http://twitter.com/oauth/authorize";);

String authUrl = httpOauthprovider.retrieveRequestToken(
httpOauthConsumer, CALLBACKURL);

this.startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(authUrl)));
Log.d(TAG, "sent doOauth");
} catch (Exception e) {
Toast.makeText(this, e.getMessage(), 
Toast.LENGTH_LONG).show();
}
Log.d(TAG, " doOauth Complete");
}

@SuppressWarnings("unused")
@Override
protected void onNewIntent(Intent intent) {

super.onNewIntent(intent);
Log.d(TAG, "onNewIntent");

Uri uri = intent.getData();

if (uri != null && uri.toString().startsWith(CALLBACKURL)) {

String verifier =
uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);

Log.d(TAG, "onNewIntent  " + " verifier " + verifier);
try {


httpOauthprovider.retrieveAccessToken(httpOauthConsumer,verifier);
String userKey = httpOauth

[twitter-dev] Android + OAuth

2009-07-29 Thread droidin.net

If you are interested on how to implement Twitter authentication with
OAuth n Android - I have the write-up in my blog http://is.gd/1S6XP