I am trying to get all the most recent and popular tweets from a particular keyword using Twitter4J, but the ones I receive are not the ones I get on Twitter when searching using the same keyword. Here is my code:
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);
}
}
On my app, when searching with proverbs as the keyword, I get this:
But on twitter, the same search yields the following results, very different to my apps results:
What am I doing wrong and what do I have to do to get the results on my app to be the same as the ones on twitter? Code would be much appreciated, thanks.
从https://twitter.com/search,我可以看到结果在几秒/分钟之内得到更新,这可能就是问题所在。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.