如何使用结构获取用户时间表?

时间:2015-08-16 05:49:28

标签: android twitter twitter-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);
    }

1 个答案:

答案 0 :(得分:2)

在您的foreach ($attribute as $attributeItem) { if (isset($this->_staticFields[$attributeItem])) { $attrField = sprintf('e.%s', $attributeItem); } else { $attributeInstance = $this->getAttribute($attributeItem); /** Add this line in code to solve the problem **/ if (!$attrInstance) return true; if ($attributeInstance->getBackend()->isStatic()) { $attrField = 'e.' . $attributeItem; } else { $this->_addAttributeJoin($attributeItem, 'left'); $attrField = $this->_getAttributeFieldName($attributeItem); } } $fullExpression = str_replace('{{attribute}}', $attrField, $fullExpression); $fullExpression = str_replace('{{' . $attributeItem . '}}', $attrField, $fullExpression); } 中,您可以搜索用户时间轴:

Timeline.java

我希望这有帮助