Reputation: 51
How to get a specific user's timeline and preview their tweets in a linear view by using fabric in android studio. There is a tutorial but its used for certain id's.
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();
}
});
}
}
Upvotes: 2
Views: 2410
Reputation: 129
Twitter Kit 1.4.0 supports Timelines:
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>
Upvotes: 3
Reputation: 2252
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 :
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
And more details for appSession, functions...: https://dev.twitter.com/twitter-kit/android/api
Upvotes: 0