I googled to get tweets of a person from Twitter API (JSON Object).
But i didn’t get any perfect solution to it.
I tried using QueryResult
, but its showing either # HASH_TAG
or @ Tag
.
Is there any way to get tweets of a person (I have the User ID and Screen Name).
Here is the code I tried:
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
User user;
AccessToken accessToken = new AccessToken(TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET);
Twitter twitter = new TwitterFactory(builder.build()).getInstance(accessToken);
List<twitter4j.Status> statusList = new ArrayList<>();
Query query = new Query("%23tarak9999");
query.setCount(20);
QueryResult result = twitter.search(query);
statusList = result.getTweets();
Thank You
2
Answers
The answer mentioned above by
Malik Ahsan
is throwing an errorRunTimeError: Must initialize Twitter before using getInstance()
.Adding the below lines solved the issue:
The above lines to be added above
UserTimeline userTimeline = new UserTimeline.Builder().screenName("SCREEN_NAME").build();
Here is an example Activity setting up a UserTimeline:
and the corresponding XML layout timeline.xml, showing attribute values without resource references for clarity: