I have started learning Twitter4j API and have got all credentials and tokens from Twitter to use it.
Now i am trying to get a timeline of my friend using a simple java program and print it on console.
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessSecret);
try
{
TwitterFactory factory = new TwitterFactory(cb.build());
Twitter twitter = factory.getInstance();
String[] srch = new String[] {"usernameoffriend"};
ResponseList<User> users = twitter.lookupUsers(srch);
for (User user : users) {
System.out.println("Friend's Name " + user.getName()); // this print my friends name
if (user.getStatus() != null)
{
System.out.println("Friend timeline");
List<Status> statusess = twitter.getFriendsTimeline();
for (Status status3 : statusess)
{
System.out.println(status3.getText());
}
}
}
The code is not giving errors. But instead of printing my Friend’s Timeline it is printing MY own Timeline.
I am using getFriendsTimeline() . Then why it is not printing my Friend’s Timeline.
Thank you in advance.
getFriendsTimeline()is deprecated on the latest build of twitter4j, usegetUserTimeLine();So to get TimeLine of friend:
getUserTimeline("pseudo")