我正在尝试使用Twitter4J从特定关键字获取所有最新和最受欢迎的推文,但我收到的不是我在Twitter上使用相同关键字搜索时获得的推文。这是我的代码:
public class Wisdom extends SherlockActivity {
Context mContext;
Twitter mTwitter;
ListView mListView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hastag_wisdom);
mListView = (ListView) findViewById(R.id.listView1);
mContext = getApplicationContext();
mTwitter = getTwitter();
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
showTweetsAbout("proverb");
}
private Twitter getTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(xxxxxxx);
cb.setOAuthConsumerSecret(xxxxxxx);
cb.setOAuthAccessToken(xxxxxxx);
cb.setOAuthAccessTokenSecret(xxxxxxx);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
return twitter;
}
private void showTweetsAbout(String queryString) {
ArrayList<String> tweetsArray = new ArrayList<String>();
Twitter twitter = mTwitter;
Query query = new Query(queryString);
query.setResultType(Query.MIXED);
query.setCount(30);
QueryResult result;
try {
result = twitter.search(query);
for (Status tweet : result.getTweets()) {
Log.d("Wisdom", tweet.getUser() + ":" + tweet.getText());
tweetsArray.add(tweet.getText());
for (URLEntity urle : tweet.getURLEntities()) {
System.out.println(urle.getDisplayURL());
}
}
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ArrayAdapter<String> tweetsAdapter = new ArrayAdapter<String>(this,
R.layout.row, tweetsArray);
mListView.setAdapter(tweetsAdapter);
}
}
在我的应用中,当使用谚语作为关键字进行搜索时,我得到了这个:
但在Twitter上,同样的搜索会产生以下结果,与我的应用结果大不相同:
我做错了什么以及我必须做些什么才能让我的应用上的结果与推特上的结果相同? 代码非常感谢,谢谢。