如何通过在android studio中使用fabric获取特定用户的时间轴并在线性视图中预览他们的推文。有一个教程,但它用于某些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();
}
});
}
}
答案 0 :(得分:3)
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>
答案 1 :(得分:0)
有很多方法可以做到这一点,但是首先你需要创建一个AppSession(登录按钮......)然后你搜索用户(在我的例子中是&#34; Almounir&#34;),这里是一个我的应用程序中的代码:
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(...);
}
}
);
}
您可以查看此示例https://github.com/twitterdev/cannonball-android
有关appSession的详细信息,功能......:https://dev.twitter.com/twitter-kit/android/api