在Twitter中,有很多公司都有自己的个人资料(例如:https://twitter.com/starbucks或https://twitter.com/mcdonalds)。我想从公司简介中获取最新推文。我有下面的代码使用JSON,但它返回一般搜索与最新推文的关键字。
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
String urlstr = "http://twitter.com/search.json?q=";
StringBuffer buff = new StringBuffer();
System.out.print("Search for : ");
urlstr += in.readLine();
URL url = new URL(urlstr);
BufferedReader br = new BufferedReader(
new InputStreamReader(
url.openConnection().getInputStream()));
int c;
while((c=br.read())!=-1)
{
buff.append((char)c);
}
br.close();
JSONObject js = new JSONObject(buff.toString());
JSONArray tweets = js.getJSONArray("results");
JSONObject tweet;
for(int i=0;i<tweets.length();i++) {
tweet = tweets.getJSONObject(i);
System.out.println((i+1)+") "+tweet.getString("from_user")+" at
"+tweet.getString("created_at"));
System.out.println(tweets.getJSONObject(i).getString("text")+"\n");
}
}
答案 0 :(得分:0)
正确的网址是 String urlstr =“http://search.twitter.com/search.json?q=from%3AMcDonalds”;