【问题标题】:Twitter4j getting friends timelineTwitter4j 交友时间线
【发布时间】:2015-05-23 00:30:21
【问题描述】:

我正在尝试从我的朋友推特帐户收集信息,目前我能够收集关注者数量、关注者和创建日期,但我无法获得时间线。我如何才能从时间线中获取推文。

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);
 }
}
}

【问题讨论】:

  • 我在 Twitter4J 的 User 类中没有看到 getuserTimeline() 方法。

标签: java api twitter twitter-oauth twitter4j


【解决方案1】:

试试这个工作代码。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-22
    • 2012-02-12
    • 1970-01-01
    • 1970-01-01
    • 2013-01-13
    • 1970-01-01
    • 2013-09-06
    • 2010-10-08
    相关资源
    最近更新 更多