我想使用 Twitter4J 获得带有“谚语”标签的最新和最受欢迎的推文,但是当我尝试这样做时,我得到的结果并不是最新和最受欢迎的(我知道这是因为我将它们与结果进行了比较我在推特上搜索相同的标签时得到了它们,它们不一样)。这是我的代码:
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("#proverbs");
}
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);
}
}
代码也将不胜感激作为解释,谢谢。