WHy am I get this error : java.lang.IllegalArgumentException: This consumer expects requests of type org.apache.http.HttpRequest
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer (CONSUMER_KEY,CONSUMER_SECRET);
consumer.setTokenWithSecret(oaut_token, tokenSecret);
URL url = new URL(targetURL);
request = (HttpURLConnection) url.openConnection();
// sign the request
consumer.sign(request);
// send the request
request.connect();
EDIT:
Just updating the accepted answer as it is not relevant anymore. the signpost documentation is a bit outdated and suggest to use CommonsHttpOAuthConsumer in Android due to bugs on HttpURLConnection. These have been fixed and now Android removed the Apache HTTP so the correct way to deal with signpost is now via DefaultOAuthConsumer.
DefaultOAuthConsumer consumer = new DefaultOAuthConsumer (CONSUMER_KEY,CONSUMER_SECRET);
consumer.setTokenWithSecret(oaut_token, tokenSecret);
URL url = new URL(targetURL);
request = (HttpURLConnection) url.openConnection();
// sign the request
consumer.sign(request);
Signpost is trivial to use on android, lol, once you get past the tutorials that are not really up to date, or complete, or in particularly useful order.
Anyway here is one way to do this using apache http instead of native android, it’s a bit ugly for the sake of brevity but should get you up and running.
Modifed your code a bit to make it work, you probably want to make the HttpClient consistent across calls but I just inlined all that. I also notice you are deserializing the tokens so I am just going to assume that you have the actual OAuth flow working.
Good luck!
That’s it