简体   繁体   English

使用Fabric Android获取用户时间线中的推文列表

[英]Get list of tweets in user time line using Fabric Android

I use the following code: 我使用以下代码:

UserTimeline userTimeline = new UserTimeline.Builder().screenName("ZainAlabdin878").build();
final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(MainActivity.this, userTimeline);
System.out.println(adapter.getCount()+"");

I get the output 0 although I have tweets. 虽然我有推文,但我得到输出0。

Am I doing something wrong? 难道我做错了什么? what I am trying to achieve is to get a list of tweets of a certain user. 我想要实现的是获取某个用户的推文列表。 I'm using android studio and plugin. 我正在使用android studio和插件。

*my goal is not to display the list but rather to get a List *我的目标不是显示列表而是获取列表

many thanks. 非常感谢。

final TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(context, new Twitter(authConfig), new TweetUi());

    TwitterCore.getInstance().logInGuest(new Callback<AppSession>() {
        @Override
        public void success(Result<AppSession> result) {
            AppSession session = result.data;
            TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient(session);
            twitterApiClient.getStatusesService().userTimeline(tweetId, screenName, tweetCount, null, null, false, false, false, true, new Callback<List<Tweet>>() {
                @Override
                public void success(Result<List<Tweet>> listResult) {
                    for (Tweet tweet : listResult.data) {
                     // here you will get list
                    }
                }

                @Override
                public void failure(TwitterException e) {
                    e.printStackTrace();
                }
            });
        }

        @Override
        public void failure(TwitterException e) {
            Log.e(TAG, "Load Tweet failure", e);
        }
    });

more details available here 更多细节在这里

Here's the code you'll need to actually fetch the Tweet objects: 这是实际获取Tweet对象所需的代码:

ArrayList<Tweet> tweets = new ArrayList<>();
TwitterCore.getInstance().getApiClient(session).getStatusesService()
    .userTimeline(null,
            "screenname",
            10 //the number of tweets we want to fetch,
            null,
            null,
            null,
            null,
            null,
            null,
            new Callback<List<Tweet>>() {
                @Override
                public void success(Result<List<Tweet>> result) {
                    for (Tweet t : result.data) {
                        tweets.add(t);
                        android.util.Log.d("twittercommunity", "tweet is " + t.text);
                    }
                }

                @Override
                public void failure(TwitterException exception) {
                    android.util.Log.d("twittercommunity", "exception " + exception);
                }
            });

You'll need to run this in a new Thread (not the UI Thread) 你需要在一个新线程(而不是UI线程)中运行它

EDIT 编辑

*Technically you don't have to run this in a new thread because it's asynchronous (someone please correct me here if I'm wrong). *技术上可以不必在一个新的线程中运行,是因为它是异步的(有人请纠正我在这里,如果我错了)。 I know other Twitter API calls are async, so I'm assuming this one is too, although I cannot find where the actual call is happening in the Fabric source..* 我知道其他Twitter API调用是异步的,所以我假设这个也是,虽然我找不到Fabric源中实际调用的位置。*

Here's the full list of parameters for userTimeline() from the Fabric SDK 以下是Fabric SDK中userTimeline()的完整参数列表

void userTimeline(@Query("user_id") Long var1, @Query("screen_name") String var2, @Query("count") Integer var3, @Query("since_id") Long var4, @Query("max_id") Long var5, @Query("trim_user") Boolean var6, @Query("exclude_replies") Boolean var7, @Query("contributor_details") Boolean var8, @Query("include_rts") Boolean var9, Callback<List<Tweet>> var10);

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

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