简体   繁体   English

显示Twitter用户的时间线

[英]Displaying A Twitter User's Timeline

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. 我已经成功完成了这个: http//www.sitepoint.com/loading-twitter-data-into-android-with-lists/ tutorial并让我的应用程序根据搜索条件显示推文。

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: 从那个教程我用这个替换了我的get行:

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. 我在listview中没有得到任何结果。我不需要验证用户名和密码,因为我想要做的就是显示时间轴,而不是操纵它。

If you are using Twitter4j this is pretty easy : 如果您使用的是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);
            }
        }
    }

Sample taken from here 这里取样

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 twitter4j jar文件 - http://twitter4j.org/archive/twitter4j-3.0.3.zip

To register your app go to dev.twitter.com 要注册您的应用程序,请访问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 我们可以使用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());
    }

Twitter has introduced Fabric SDK for needs like yours. Twitter已经为您的需求推出了Fabric SDK。 Here is a site: Twitter Fabric . 这是一个网站: Twitter Fabric When you install SDK you will have new icon in your Android studio for Fabric Sdk. 安装SDK时,您的Android工作室将为Fabric Sdk添加新图标。 You have to install Twitter kit and use embed tweets. 您必须安装Twitter工具包并使用嵌入推文。 For user timeline you have to use UserTimeline. 对于用户时间线,您必须使用UserTimeline。 Also , you have some project in github that can help you understand how Twitter kit works: Github repo 此外,您在github中有一些项目可以帮助您了解Twitter工具包的工作原理: Github repo

you can get the answer of ur question at https://github.com/robhinds/AndroidTwitterDemo 你可以在https://github.com/robhinds/AndroidTwitterDemo上找到你的问题的答案

or 要么

http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html http://automateddeveloper.blogspot.com/2011/06/android-twitter-oauth-authentication.html

use twitter4j jar for same 使用twitter4j jar也一样

hope will help u ... 希望能帮到你......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM