Twitter4j获得朋友时间表

时间:2015-03-19 18:26:03

标签: java api twitter twitter-oauth twitter4j

我正在尝试从我的朋友Twitter帐户收集信息,目前我能够收集关注者的数量,关注和创建日期,但我无法获得时间表。我怎么能从时间线上得到推文。

import twitter4j.TwitterFactory;
import twitter4j.User;
import twitter4j.Twitter;
import twitter4j.TwitterException;


public class testing {

public static void main(String[] args) {

try {

Twitter twitter = new TwitterFactory().getInstance();
User user = twitter.showUser(098765432);
System.out.println(user.getDescription());
System.out.println(user.getCreatedAt());
System.out.println(user.getFollowersCount());
System.out.println(user.getFriendsCount());



 }catch (TwitterException te) {
 te.printStackTrace();
 System.out.println("Failed to delete status: " + te.getMessage());
 System.exit(-1);
 }
}
}

1 个答案:

答案 0 :(得分:0)

试试这个有效的代码。

public class TwitterDemo {

static String consumerKeyStr = "Paste your consumer key here";
static String consumerSecretStr = "Paste your consumer key secret here here";
static String accessTokenStr = "Paste your access token key here";
static String accessTokenSecretStr = "paste your access token secret here";

public static void main(String[] args) {

    try {
         List<Status> statuses;

        Twitter twitter = new TwitterFactory().getInstance();

        twitter.setOAuthConsumer(consumerKeyStr, consumerSecretStr);
        AccessToken accessToken = new AccessToken(accessTokenStr,
                accessTokenSecretStr);

        twitter.setOAuthAccessToken(accessToken);

        String searchuser[] = {"jack"};
        ResponseList<User> users_list = twitter.lookupUsers(searchuser);

        for (User user : users_list) {

        statuses = twitter.getUserTimeline(user.getName());
        System.out.println("Showing user timeline.");
        for (Status status : statuses) {
            System.out.println(status.getUser().getScreenName() + " : " + status.getText());
        }
    }

    } catch (TwitterException te) {
        te.printStackTrace();
    }
  }

}

输出:

Showing Jack timeline.

jack : http://t.co/voJLHwpO1F
jack : http://t.co/VpH6Ub0Qyo
jack : This changes everything! https://t.co/WaEJdMWV1V
jack : RT @pandemona: i have news that i am SO excited to share. i've joined @periscopeco. this also means i've come home to @twitter!!
jack : RT @periscopeco: You may have heard some news: It involves a blue bird. #YouCanGuessTheRest #WeJoinedTheFlockInJanuary #AreWeUsingThisRight…
jack : RT @repjohnlewis: We cannot allow the actions of a violent few to derail the progress of a nonviolent movement #Ferguson
jack : RT @nytimes: The artists of earth and sky http://t.co/TXeksfMUjR http://t.co/2V1mNSZ68B
jack : RT @NancyPelosi: Happy Birthday, @GirlScouts! Your leadership, service (and delicious cookies!) inspire us all! Congrats on 103 years. #Gir…
jack : RT @ryanjreilly: #Ferguson chief’s actions uncovered in DOJ report made it pretty untenable for him to stay http://t.co/9l0OQZitFv http://t…
jack : RT @tchopstl: This is what the DoJ's report said about Tom Jackson's FPD supervisors, one of whom will be appointed interim chief. http://t…
jack : RT @AntonioFrench: #ChiefJacksonHighlights