必须在Android代码中的Fabric.with()异常中启动TweetUi Kit吗?

时间:2016-02-19 00:08:28

标签: java android twitter twitter-fabric

嘿所以我正在构建一个应用程序,并试图将Twitter提要加入应用程序,我正在使用Fabric来做到这一点。我已正确安装并且一切正常,但是当我尝试运行以下内容时,这是来自https://docs.fabric.io/android/twitter/show-timelines.html的示例

我得到以下异常:

java.lang.IllegalStateException: Must start TweetUi Kit in Fabric.with().

任何想法?

package com.android.twitterApp;

import io.fabric.sdk.android.Fabric;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;

import com.android.twitterApp.R;
import com.digits.sdk.android.Digits;
import com.twitter.sdk.android.core.TwitterAuthConfig;
import com.twitter.sdk.android.core.TwitterCore;
import com.twitter.sdk.android.tweetui.TweetTimelineListAdapter;
import com.twitter.sdk.android.tweetui.UserTimeline;



public class TwitterAPIActivity extends ListActivity {

// Note: Your consumer key and secret should be obfuscated in your source code before shipping.

private static final String TWITTER_KEY = "**********";
private static final String TWITTER_SECRET = "*********";

private Intent intent;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new TwitterCore(authConfig), new Digits());

    setContentView(R.layout.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)

Fabric SDK将功能分为称为Kits的模块。您必须通过Fabric.with()指明您希望使用哪些套件。这通常通过扩展Android的Application类来完成。

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();

        TwitterAuthConfig authConfig = 
                   new TwitterAuthConfig("consumerKey",
                                         "consumerSecret");

        Fabric.with(this, new Twitter(authConfig));

        // Example: multiple kits
        // Fabric.with(this, new Twitter(authConfig),
        //                  new Crashlytics());
    }
}

更多信息:https://dev.twitter.com/twitter-kit/android/integrate

请参阅以下网站上的规范示例应用:https://github.com/twitterdev/cannonball-android