Twitter Android SDK 未执行回调

Twitter Android SDK not executing Callback

我 运行 我很确定这段带有 Twitter 句柄的代码不存在,以便测试错误处理。回调上的断点永远不会命中,无论是成功还是失败。

关于这是为什么的任何指示?

请注意,此代码适用于有效的 Twitter 句柄,但也不会调用回调。

final Callback<Tweet> actionCallback = new Callback<Tweet>() {
    @Override
    public void success(Result<Tweet> result) {
        int x = 1;
        x++; // This code is just so I can put a breakpoint here
    }
    @Override
    public void failure(TwitterException exception) {
        DialogManager.showOkDialog(context, R.string.twitter_feed_not_found);
    }
};

final UserTimeline userTimeline = new UserTimeline.Builder().screenName(handleStr + "dfdfddfdfdfasdf") // Handle that doesn't exist
        .includeReplies(false).includeRetweets(false).maxItemsPerRequest(5).build();

final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(context)
        .setTimeline(userTimeline)
        .setViewStyle(R.style.tw__TweetLightWithActionsStyle)
        .setOnActionCallback(actionCallback)
        .build();

listView.setAdapter(adapter);

我认为您误解了 actionCallback 的用途。从 TweetTimelineListAdapter 的源代码中,您可以看到此回调用于推文视图上的操作,例如,当您单击收藏图标时。我用最喜欢的图标进行了测试,回调被调用了。

在源代码的getView方法中查看此评论。

   /**
     * Returns a CompactTweetView by default. May be overridden to provide another view for the
     * Tweet item. If Tweet actions are enabled, be sure to call setOnActionCallback(actionCallback)
     * on each new subclass of BaseTweetView to ensure proper success and failure handling
     * for Tweet actions (favorite, unfavorite).
     */

回调并非旨在处理不存在的屏幕名称,实际上是特定推文的 actions/buttons。

希望对您有所帮助。

更新:您不需要检测 UserTimeLine 上的任何错误,因为构建器不会抛出任何异常并且适配器将为空,屏幕上不会显示 rows/views。但是如果你仍然需要在加载中检测一些 "error" 你必须依赖 UserTimeLine 的 "next" 方法。

看看

  userTimeline.next(null, new Callback<TimelineResult<Tweet>>() {
        @Override
        public void success(Result<TimelineResult<Tweet>> result) {

        }

        @Override
        public void failure(TwitterException exception) {
            Log.d("TAG",exception.getMessage());
        }
    });

此方法显示用户的下一条推文,如果失败回调被调用,您将确定该用户没有任何推文或用户不存在。