简体   繁体   English

如何在Android Studio中使用Fabric获取特定用户的时间轴并查看其推文?

[英]How to get a specific user's timeline and view their tweets by using fabric in android studio?

How to get a specific user's timeline and preview their tweets in a linear view by using fabric in android studio. 如何通过使用Android Studio中的结构获取特定用户的时间轴并以线性视图预览其推文。 There is a tutorial but its used for certain id's. 有一个教程,但用于某些ID。

public class TweetListActivity extends ListActivity {
    List<Long> tweetIds = Arrays.asList(503435417459249153L,
            510908133917487104L,
            473514864153870337L,
            477788140900347904L);



    final TweetViewFetchAdapter adapter =
            new TweetViewFetchAdapter<CompactTweetView>(
                    TweetListActivity.this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tweet_list);
        setListAdapter(adapter);
        adapter.setTweetIds(tweetIds,
                new LoadCallback<List<Tweet>>() {
                    @Override
                    public void success(List<Tweet> tweets) {
                        // my custom actions
                    }

                    @Override
                    public void failure(TwitterException exception) {
                        // Toast.makeText(...).show();
                    }
                });
    }
}

Twitter Kit 1.4.0 supports Timelines: Twitter Kit 1.4.0支持时间表:

UserTimeline userTimeline = new UserTimeline.Builder().screenName("fabric").build();

-- -

import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class TimelineActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timeline);

        final UserTimeline userTimeline = new UserTimeline.Builder()
            .screenName("fabric")
            .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(this, userTimeline);
        setListAdapter(adapter);
    }
}

-- -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView android:id="@id/android:empty"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:gravity="center_horizontal|center_vertical"
              android:text="@string/timeline_empty"/>

    <ListView android:id="@id/android:list"
              android:layout_width="match_parent"
              android:layout_height="0dp"
              android:layout_weight="1"
              android:divider="@color/divider_gray"
              android:dividerHeight="@dimen/divider_height"
              android:drawSelectorOnTop="false"/>
</LinearLayout>

there is many ways to do it, but 1st you need to create an AppSession (login button...) then you search for the user(in my example is "Almounir"), here is a code from my app to do it : 有很多方法可以做到,但是首先您需要创建一个AppSession(登录按钮...),然后搜索用户(在我的示例中是“ Almounir”),这是我的应用程序执行的代码:

private static final String SEARCH_QUERY = "Almounir";
private static final String SEARCH_RESULT_TYPE = "recent";
private static final int SEARCH_COUNT = 20;
private long maxId;

private void loadTweets() {


final SearchService service = Twitter.getApiClient().getSearchService();
service.tweets(SEARCH_QUERY, null, null, null, SEARCH_RESULT_TYPE, SEARCH_COUNT, null, null,
        maxId, true, new Callback<Search>() {
            @Override
            public void success(Result<Search> searchResult) {

               //Do something with result
            }

            @Override
            public void failure(TwitterException error) {

                Toast.makeText(...); 
            }
        }
);

} }

you can look at this example https://github.com/twitterdev/cannonball-android 你可以看一下这个例子https://github.com/twitterdev/cannonball-android

And more details for appSession, functions...: https://dev.twitter.com/twitter-kit/android/api 以及有关appSession,函数的更多详细信息...: https ://dev.twitter.com/twitter-kit/android/api

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

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