如何使用 fabric 获取用户时间线?
How to get user timeline using fabric?
我正在尝试使用 Fabric 开发 Twitter 应用程序。我查看了 Fabric 文档 (http://docs.fabric.io/android/twitter/show-timelines.html) 并将代码集成到我的 application.But 我无法得到结果。在主要 activity 中,我可以在我想将 activity 重定向到另一个 activity 上的时间线 activity.However 后使用 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);
}
希望对您有所帮助
我正在尝试使用 Fabric 开发 Twitter 应用程序。我查看了 Fabric 文档 (http://docs.fabric.io/android/twitter/show-timelines.html) 并将代码集成到我的 application.But 我无法得到结果。在主要 activity 中,我可以在我想将 activity 重定向到另一个 activity 上的时间线 activity.However 后使用 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);
}
希望对您有所帮助