Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 1.57 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Fetch Twitter feed on Android - rate limit exceeded on device?
  2. public ArrayList<Tweet> getTweets() {
  3.  
  4.       ArrayList<Tweet> tweets =
  5.             new ArrayList<Tweet>();
  6.  
  7.       HttpClient client = new  DefaultHttpClient();
  8.       HttpGet get = new HttpGet(twitterUrl);
  9.  
  10.       ResponseHandler<String> responseHandler =
  11.             new BasicResponseHandler();
  12.  
  13.       String responseBody = null;
  14.       try {
  15.         responseBody = client.execute(get, responseHandler);
  16.       } catch(Exception ex) {
  17.         ex.printStackTrace();
  18.         timeOut = true;
  19.       }
  20.  
  21.       JSONObject jsonObject = null;
  22.     JSONArray arr = null;
  23.     try {
  24.         arr = new JSONArray(responseBody);
  25.     } catch (JSONException e1) {
  26.         e1.printStackTrace();
  27.         timeOut = true;
  28.     }
  29.  
  30.       for (int i = 0; i < arr.length(); i++) {
  31.             try {
  32.                 jsonObject = arr.getJSONObject(i);
  33.             } catch (JSONException e1) {
  34.                 e1.printStackTrace();
  35.                 timeOut = false;
  36.             }
  37.             Tweet tweet = null;
  38.             try {
  39.                 tweet = new Tweet(
  40.                       jsonObject.getJSONObject("user").getString("name"),
  41.                       jsonObject.getString("text"),
  42.                       jsonObject.getJSONObject("user").getString("profile_image_url"),
  43.                       twitterHumanFriendlyDate(jsonObject.getString("created_at"))
  44.                 );
  45.             } catch (JSONException e) {
  46.                 e.printStackTrace();
  47.                 timeOut = true;
  48.             }
  49.             tweets.add(tweet);
  50.         }
  51.  
  52.       return tweets;
  53.     }