Monday, April 15, 2013

[android help] How can I fetch all tweets from a particuler user and place them in my Android layout?

twitter - How can I fetch all tweets from a particuler user and place them in my Android layout? - Stack Overflow



















I am able to fetch the last tweet by a particular user and place that in my Android layout. However, I need to fetch all tweets by that user and display them in the layout.


Here is my code so far:



httpClient = new DefaultHttpClient();
tweetList = (TextView) findViewById(R.id.tvTweet);
new ReadJSON().execute("text");

public org.json.JSONObject alltweets(String username) throws ClientProtocolException, IOException, JSONException {
StringBuilder sb = new StringBuilder(URL);
sb.append(username);
HttpGet get = new HttpGet(sb.toString());
HttpResponse response = httpClient.execute(get);
int statuss = response.getStatusLine().getStatusCode();
if (statuss == 200) {
int i;
HttpEntity e = response.getEntity();
String data = EntityUtils.toString(e);
JSONArray timeline = new JSONArray(data);
for (i=0; i alltweets = timeline.getJSONObject(i);
Log.i("tweet", timeline.getJSONObject(i) + "");
}
return alltweets;
} else {
return null;
}
}

public class ReadJSON extends AsyncTask {
@Override
protected String doInBackground(String...params) {
// TODO Auto-generated method stub
try {
json = alltweets("username"); //particular user name from which page you want to fetch tweets
return json.getString("text");
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
Log.i("tweet is ", result);
tweetList.setText(result);
}
}


















Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.










default






.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...