0
我想用Twitter4J獲得最新和最流行的Twitter標籤「箴言」推文,但是當我嘗試這樣做時,我得到的結果不是最新和最流行(我知道,因爲我將它們與我在Twitter上搜索相同標籤時得到的結果進行了比較,結果並不相同)。這裏是我的代碼:Android 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);
}
}
代碼也將不勝感激膨脹作爲解釋,謝謝。
不,還沒有工作;給出相同的結果 – AndroidDev