[英]Getting tweets with specific hashtag from a user's timeline using Fabric in android
[英]How to get a specific user's timeline and view their tweets by using fabric in android studio?
如何通過使用Android Studio中的結構獲取特定用戶的時間軸並以線性視圖預覽其推文。 有一個教程,但用於某些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支持時間表:
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>
有很多方法可以做到,但是首先您需要創建一個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(...);
}
}
);
}
你可以看一下這個例子https://github.com/twitterdev/cannonball-android
以及有關appSession,函數的更多詳細信息...: https ://dev.twitter.com/twitter-kit/android/api
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.