![](/img/trans.png)
[英]How to get a specific user's timeline and view their tweets by using fabric in android studio?
[英]How to get user timeline using fabric?
我正在嘗試使用Fabric開發Twitter應用程序。 我查看了Fabric文檔( http://docs.fabric.io/android/twitter/show-timelines.html ),並將代碼集成到了我的應用程序中。但是我沒有得到結果。 在主要活動中,我想將活動重定向到時間軸活動后可以使用Twitter帳戶登錄。但是在其他活動上,似乎沒有任何事情。 我怎么了 這是我的代碼。 謝謝!
MainActivity.xml
<com.twitter.sdk.android.core.identity.TwitterLoginButton
android:id="@+id/twitter_login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"/>
MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
Fabric.with(this, new Twitter(authConfig));
setContentView(R.layout.activity_main);
loginButton = (TwitterLoginButton) findViewById(R.id.twitter_login_button);
loginButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
// Do something with result, which provides a TwitterSession for making API calls
Toast.makeText(getApplicationContext(), "Login Succeed", Toast.LENGTH_LONG).show();
Intent timeLine = new Intent(MainActivity.this, Timeline.class);
startActivity(timeLine);
}
Timeline.xml
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:text="No Tweets"/>
<ListView android:id="@id/android:list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#e1e8ed"
android:dividerHeight="1dp"
android:drawSelectorOnTop="false"/>
Timeline.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_timeline);
final UserTimeline userTimeline = new UserTimeline.Builder()
.screenName("fabric")
.build();
final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
.setTimeline(userTimeline)
.build();
setListAdapter(adapter);
}
在您的Timeline.java
您可以搜索用戶時間軸:
private static final String SEARCH_QUERY = "almounir"; //the user name
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_timeline);
ListView lv = (ListView) findViewById(R.id.list);
//lv.setEmptyView(findViewById(R.id.loading)); d'ont forget to add loading pic
SearchTimeline searchTimeline = new SearchTimeline.Builder().query(SEARCH_QUERY).build();
final TweetTimelineListAdapter timelineAdapter = new TweetTimelineListAdapter(this, searchTimeline);
lv.setAdapter(timelineAdapter);
}
我希望這有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.