简体   繁体   中英

Android: Fabric User Timeline Not Working

I followed the documentation and my project appeared to get set up just fine. However, when i run the project The app is displaying the "No Tweets' TextView, not a timeline. My code is basically what was in the doc, just cuz i wanna see it get working first before i do anything else.

Here's my Activity's onCreate:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_social);


    try{
        TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
        Fabric.with(this, new Twitter(authConfig));

        final UserTimeline userTimeline = new UserTimeline.Builder()
                .screenName("fabric")
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter(this, userTimeline);

        setListAdapter(adapter);
    }catch(Exception ex){

    }

And here is my XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="org.witrackclub.wtc.SocialActivity"
tools:showIn="@layout/activity_social">

<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"/>

</LinearLayout>

Help would be much appreciated

Well, I think that is a problem with your keys (consumerKey & consumerSecret).

AndroidManifest.xml

<application
    ...
    android:name="TimeLineFabricApplication"
    ...

The Application: TimeLineFabricApplication.java

import android.app.Application;
import com.twitter.sdk.android.Twitter;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import io.fabric.sdk.android.Fabric;

public class TimeLineFabricApplication extends Application{

    @Override
    public void onCreate() {
        super.onCreate();

        TwitterAuthConfig authConfig =  new TwitterAuthConfig("consumerKey", "consumerSecret");
        Fabric.with(this, new Twitter(authConfig));
    }
}

The Activity: MainActivity.java

import android.app.ListActivity;
import android.os.Bundle;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;

public class MainActivity extends ListActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final UserTimeline userTimeline = new UserTimeline.Builder()
            .screenName("fabric")
            .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this)
            .setTimeline(userTimeline)
            .build();
        setListAdapter(adapter);
    }
}

And the Layout: activity_main.xml

<?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="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"/>
</LinearLayout>

My result:

我的结果

the keys that helped me was that I found myself in fabric.io of the created application. Are you sure you created an app on Fabric.io with your user?

In the LogCat or AndroidMonitor, You see something like: Failed to get app auth token com.twitter.sdk.android.core.TwitterApiException: 403 Forbidden

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM