Search code examples
androidtwitterandroidhttpclient

Getting last tweet on android (API 1.1)


I am using the following method for making an android app:

public JSONObject lastTweet(String username) throws ClientProtocolException, IOException, JSONException {
    String url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=hodorhodorhodor";
    HttpClient client = new DefaultHttpClient();    
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get); //cannot execute this line
    int status = response.getStatusLine().getStatusCode();
    //Some more code
}

When I run the app, I get an error that the app has stopped working. After some debugging I found that the following is the line (which I have also mentioned in the above code) where my app gets stuck:

HttpResponse response = client.execute(get);

After some search online I found that it has got to do something with the twitter API 1.1 which requires some sort of OAuth authentication. Can anyone please help me here?

Thanks.


Solution

  • As previously discussed on official Twitter forums, it is by now required to utilise OAuth for all methods in API 1.1 which leaves some constraints.

    You can although use this library to receive an access token and as stated in the library: Just implement TwitterOAuthView.Listener and call start() method.

    This blog post is furthermore a complete tutorial on utilising a twitter access token to login and writing an update to twitter.

    Hope this helps.