将 Twitter API 与 Fabric 结合使用

Using Twitter API with Fabric

调试程序时获取推文,但当我只 运行 说 "Unfortunately, APP has stopped."

private void CargarTweets() {
    setProgressBarIndeterminateVisibility(true);

    myLayout.removeAllViews();

    StatusesService statusesService = Twitter.getApiClient().getStatusesService();

    statusesService.userTimeline(null,"wgcv",10,null,null,null,null,null,null, new Callback<List<Tweet>>() {

        @Override
        public void success(Result<List<Tweet>> listResult) {
            setProgressBarIndeterminateVisibility(false);

            for (Tweet tweet : listResult.data) {
                myLayout.addView(
                        new CompactTweetView(Principal.this, tweet));
            }
        }

        @Override
        public void failure(TwitterException e) {

        }
    });

Logcat:

03-13 13:49:09.937    3093-3093/me.wgcv.emergenciasgye E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: me.wgcv.emergenciasgye, PID: 3093
    java.lang.IllegalArgumentException: MetricsManager may not be null
            at com.twitter.sdk.android.tweetui.internal.TweetViewMetric.<init>(TweetViewMetric.java:30)
            at com.twitter.sdk.android.tweetui.BaseTweetView.getTweetViewMetric(BaseTweetView.java:355)
            at com.twitter.sdk.android.tweetui.BaseTweetView.initComponents(BaseTweetView.java:347)
            at com.twitter.sdk.android.tweetui.BaseTweetView.<init>(BaseTweetView.java:135)
            at com.twitter.sdk.android.tweetui.BaseTweetView.<init>(BaseTweetView.java:115)
            at com.twitter.sdk.android.tweetui.BaseTweetView.<init>(BaseTweetView.java:105)
            at com.twitter.sdk.android.tweetui.CompactTweetView.<init>(CompactTweetView.java:19)
            at me.wgcv.emergenciasgye.Principal.success(Principal.java:66)
            at com.twitter.sdk.android.core.Callback.success(Callback.java:23)
            at retrofit.CallbackRunnable.run(CallbackRunnable.java:45)
            at android.os.Handler.handleCallback(Handler.java:739)
            at android.os.Handler.dispatchMessage(Handler.java:95)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

添加APPSESION

    TwitterCore.getInstance().logInGuest(new Callback() {
        @Override
        public void success(Result result) {
            AppSession guestAppSession = (AppSession) result.data;
            TwitterApiClient twitterApiClient =  TwitterCore.getInstance().getApiClient(guestAppSession);
            StatusesService statusesService = Twitter.getApiClient().getStatusesService();
            statusesService.userTimeline(382469423L,null,10,null,null,null,null,null,null, new Callback<List<Tweet>>() {

                @Override
                public void success(Result<List<Tweet>> listResult) {
                    setProgressBarIndeterminateVisibility(false);

                    for (Tweet tweet : listResult.data) {
                        myLayout.addView(
                                new CompactTweetView(Principal.this, tweet));
                    }
                }

                @Override
                public void failure(TwitterException e) {
                    Log.e("Error","Error");
                }
            });
        }

        @Override
        public void failure(TwitterException exception) {
            // unable to get an AppSession with guest auth
        }
    });