显示 Twitter 用户的时间线

发布于 2024-12-11 02:30:23 字数 443 浏览 1 评论 0 原文

我已成功完成此操作:http://www.sitepoint。 com/loading-twitter-data-into-android-with-lists/ 教程,并让我的应用程序根据搜索条件显示推文。

我希望我的应用程序做的是显示特定用户的时间线。

从该教程中,我用以下内容替换了我的获取行:

HttpGet("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=android");

我在列表视图中没有得到任何结果。我不需要验证用户名和密码,因为我想做的只是显示时间线,而不是操纵它。

I have successfully completed this: http://www.sitepoint.com/loading-twitter-data-into-android-with-lists/ tutorial and have gotten my app to display tweets based on a search criteria.

What I want my app to do is display the timeline of a specific user.

From that tutorial I have replaced my get line with this:

HttpGet("http://api.twitter.com/1/statuses/user_timeline.json?screen_name=android");

I am getting no results in my listview.. I shouldn't need to authenticate user name and password because all I want to do is display the timeline, not manipulate it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

荒人说梦 2024-12-18 02:30:23

如果您使用 Twitter4j,这非常简单:

 public final class GetTimelines {
        /**
         * Usage: java twitter4j.examples.GetTimelines ID Password
         * @param args String[]
         */
        public static void main(String[] args) {

            Twitter unauthenticatedTwitter = new TwitterFactory()
                    .getInstance();
            System.out.println("Showing public timeline.");
            try {
                List<Status> statuses = unauthenticatedTwitter
                        .getPublicTimeline();
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                if (args.length < 2) {
                    System.out
                            .println("You need to specify TwitterID/Password combination to show UserTimelines.");
                    System.out
                            .println("Usage: java twitter4j.examples.GetTimelines ID Password");
                    System.exit(0);
                }

                // Other methods require authentication
                Twitter twitter = new TwitterFactory().getInstance(args[0],
                        args[1]);
                statuses = twitter.getFriendsTimeline();
                System.out.println("------------------------------");
                System.out.println("Showing " + args[0]
                        + "'s friends timeline.");
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                statuses = twitter.getUserTimeline();
                System.out.println("------------------------------");
                System.out.println("Showing " + args[0] + "'s timeline.");
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                Status status = twitter.showStatus(81642112l);
                System.out.println("------------------------------");
                System.out.println("Showing " + status.getUser().getName()
                        + "'s status updated at " + status.getCreatedAt());
                System.out.println(status.getText());
                System.exit(0);
            } catch (TwitterException te) {
                System.out.println("Failed to get timeline: "
                        + te.getMessage());
                System.exit(-1);
            }
        }
    }

示例取自 此处

If you are using Twitter4j this is pretty easy :

 public final class GetTimelines {
        /**
         * Usage: java twitter4j.examples.GetTimelines ID Password
         * @param args String[]
         */
        public static void main(String[] args) {

            Twitter unauthenticatedTwitter = new TwitterFactory()
                    .getInstance();
            System.out.println("Showing public timeline.");
            try {
                List<Status> statuses = unauthenticatedTwitter
                        .getPublicTimeline();
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                if (args.length < 2) {
                    System.out
                            .println("You need to specify TwitterID/Password combination to show UserTimelines.");
                    System.out
                            .println("Usage: java twitter4j.examples.GetTimelines ID Password");
                    System.exit(0);
                }

                // Other methods require authentication
                Twitter twitter = new TwitterFactory().getInstance(args[0],
                        args[1]);
                statuses = twitter.getFriendsTimeline();
                System.out.println("------------------------------");
                System.out.println("Showing " + args[0]
                        + "'s friends timeline.");
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                statuses = twitter.getUserTimeline();
                System.out.println("------------------------------");
                System.out.println("Showing " + args[0] + "'s timeline.");
                for (Status status : statuses) {
                    System.out.println(status.getUser().getName() + ":"
                            + status.getText());
                }
                Status status = twitter.showStatus(81642112l);
                System.out.println("------------------------------");
                System.out.println("Showing " + status.getUser().getName()
                        + "'s status updated at " + status.getCreatedAt());
                System.out.println(status.getText());
                System.exit(0);
            } catch (TwitterException te) {
                System.out.println("Failed to get timeline: "
                        + te.getMessage());
                System.exit(-1);
            }
        }
    }

Sample taken from here

手心的温暖 2024-12-18 02:30:23

如果您只想获取用户时间线,那么最好的方法是 -

twitter4j jar 文件 - http:// /twitter4j.org/archive/twitter4j-3.0.3.zip

要注册您的应用程序,请转到 dev.twitter.com

我们可以使用 twitter oauth 获取使用时间线,对于此过程,我们不需要提供任何用户凭据

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
    builder.setOAuthAccessToken(TWITTER_ACCESS_KEY);
    builder.setOAuthAccessTokenSecret(TWITTER_ACCESS_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();
    Paging page = new Paging();
    page.setCount(100);
    List<Status> statuses = new ArrayList<Status>();
    statuses = twitter.getUserTimeline("write username here", page);
    for (Status status : statuses) {
        System.out.println("title is : " + status.getText());
    }

If you just want to fetch user timeline than the best way is -

twitter4j jar file - http://twitter4j.org/archive/twitter4j-3.0.3.zip

To register your app go to dev.twitter.com

We can fetch the use timeline by using twitter oauth and for this process we don't need to provide any user credentials

    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
    builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
    builder.setOAuthAccessToken(TWITTER_ACCESS_KEY);
    builder.setOAuthAccessTokenSecret(TWITTER_ACCESS_SECRET);
    Configuration configuration = builder.build();
    TwitterFactory factory = new TwitterFactory(configuration);
    Twitter twitter = factory.getInstance();
    Paging page = new Paging();
    page.setCount(100);
    List<Status> statuses = new ArrayList<Status>();
    statuses = twitter.getUserTimeline("write username here", page);
    for (Status status : statuses) {
        System.out.println("title is : " + status.getText());
    }
淡淡绿茶香 2024-12-18 02:30:23

Twitter 推出了 Fabric SDK 来满足您的需求。这是一个网站:Twitter Fabric。当您安装 SDK 时,您将在 Android studio 中看到 Fabric Sdk 的新图标。您必须安装 Twitter 工具包并使用嵌入推文。对于用户时间线,您必须使用 UserTimeline。另外,您在 github 上有一些项目可以帮助您了解 Twitter 套件的工作原理:
Github 存储库

Twitter has introduced Fabric SDK for needs like yours. Here is a site: Twitter Fabric. When you install SDK you will have new icon in your Android studio for Fabric Sdk. You have to install Twitter kit and use embed tweets. For user timeline you have to use UserTimeline. Also , you have some project in github that can help you understand how Twitter kit works:
Github repo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文