
Untitled
By: a guest on
Apr 28th, 2012 | syntax:
None | size: 1.57 KB | hits: 16 | expires: Never
Fetch Twitter feed on Android - rate limit exceeded on device?
public ArrayList<Tweet> getTweets() {
ArrayList<Tweet> tweets =
new ArrayList<Tweet>();
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(twitterUrl);
ResponseHandler<String> responseHandler =
new BasicResponseHandler();
String responseBody = null;
try {
responseBody = client.execute(get, responseHandler);
} catch(Exception ex) {
ex.printStackTrace();
timeOut = true;
}
JSONObject jsonObject = null;
JSONArray arr = null;
try {
arr = new JSONArray(responseBody);
} catch (JSONException e1) {
e1.printStackTrace();
timeOut = true;
}
for (int i = 0; i < arr.length(); i++) {
try {
jsonObject = arr.getJSONObject(i);
} catch (JSONException e1) {
e1.printStackTrace();
timeOut = false;
}
Tweet tweet = null;
try {
tweet = new Tweet(
jsonObject.getJSONObject("user").getString("name"),
jsonObject.getString("text"),
jsonObject.getJSONObject("user").getString("profile_image_url"),
twitterHumanFriendlyDate(jsonObject.getString("created_at"))
);
} catch (JSONException e) {
e.printStackTrace();
timeOut = true;
}
tweets.add(tweet);
}
return tweets;
}