-3

我需要做的是显示一个推特提要,但也能够使用文本框和提交按钮更新我的推特。请帮忙

4

1 回答 1

0

此处的示例代码 - http://codehenge.net/blog/2011/05/android-programming-tutorial-a-simple-twitter-feed-reader/

在页面底部下载完整的 java 代码和清单。

public ArrayList<Tweet> getTweets(String searchTerm, int page) {
  String searchUrl = 
        "http://search.twitter.com/search.json?q=@" 
        + searchTerm + "&rpp=100&page=" + page;

  ArrayList<Tweet> tweets = 
        new ArrayList<Tweet>();

  HttpClient client = new  DefaultHttpClient();
  HttpGet get = new HttpGet(searchUrl);

  ResponseHandler<String> responseHandler = 
        new BasicResponseHandler();

  String responseBody = null;
  try {
    responseBody = client.execute(get, responseHandler);
  } catch(Exception ex) {
    ex.printStackTrace();
  }

  JSONObject jsonObject = null;
  JSONParser parser=new JSONParser();

  try {
    Object obj = parser.parse(responseBody);
    jsonObject=(JSONObject)obj;
  }catch(Exception ex){
    Log.v("TEST","Exception: " + ex.getMessage());
  }

  JSONArray arr = null;

  try {
    Object j = jsonObject.get("results");
    arr = (JSONArray)j;
  } catch(Exception ex){
    Log.v("TEST","Exception: " + ex.getMessage());
  }

  for(Object t : arr) {
    Tweet tweet = new Tweet(
      ((JSONObject)t).get("from_user").toString(),
      ((JSONObject)t).get("text").toString(),
      ((JSONObject)t).get("profile_image_url").toString()
    );
    tweets.add(tweet);
  }

  return tweets;
}
于 2012-09-29T17:47:45.243 回答