Twitter UserTimeline有效,但SearchTimeline似乎从未调用服务器 [英] Twitter UserTimeline works but SearchTimeline never seem to even call the server

查看:108
本文介绍了Twitter UserTimeline有效,但SearchTimeline似乎从未调用服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在文档中使用了确切的示例代码,但是对于 SearchTimeline ,即

I am using the exact example code in the documents and yet I am getting no tweets at all for SearchTimeline, i.e.

No Tweet

如果我将其替换为 UserTimeline ,则会得到结果,但是对于我的用例,我当然需要 SearchTimeline .是否有人设法使 SearchTimeline 正常工作?另外(fyi)我已经为我的应用设置了Fabric设置,并能够使用其Twitter帐户登录用户.

If I replace with UserTimeline I got results, but of course I need SearchTimeline for my use case. Has anyone managed to get SearchTimeline to work? Also (fyi) I have Fabric setup for my app and am able to login users with their twitter accounts.

确切的代码(与文档中的代码相同)失败:

The exact code, which is as from document, which fails:

public class SearchTimelineFragment extends ListFragment {

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

        final SearchTimeline searchTimeline = new SearchTimeline.Builder()
                .query("#twitterflock")
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity())
                .setTimeline(searchTimeline)
                .build();
        setListAdapter(adapter);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        return inflater.inflate(R.layout.timeline, container, false);
    }
}

如果有问题的话,我还没有PlayStore参与开发.

Also I am in development with no PlayStore presence, in case that matters.

更多信息

添加回调块不会导致失败或成功消息.好像代码完全没有执行:没有服务器调用.但是, onCreate 被调用了.再一次,如果我替换为 UserTimeline ,我会得到结果.

Adding callback block results in neither failure nor success message. It's as if the code is entirely not executed: no server call. But yet, onCreate is called. And again if I replace with UserTimeline I get results.

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate");
        final SearchTimeline searchTimeline = new SearchTimeline.Builder()
                .query("#twitterflock")
                .build();
        final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(getActivity())
                .setTimeline(searchTimeline)
                .setOnActionCallback(new Callback<Tweet>() {
                    @Override
                    public void success(Result<Tweet> result) {
                        Log.d(TAG, "SearchTimeline successful");
                    }

                    @Override
                    public void failure(TwitterException e) {
                        Log.d(TAG, "SearchTimeline failed");
                        e.printStackTrace();
                        ;
                    }
                })
                .build();
        setListAdapter(adapter);
    }

我也在使用 android.support.v4.app.ListFragment;

推荐答案

这是因为您在onCreate中设置了列表适配器,而在onCreate之后调用了onCreateView.

That is because you are setting the list adapter in onCreate, while onCreateView is called after onCreate.

在OnCreateView中设置listAdapter.

Set the listAdapter in OnCreateView.

这篇关于Twitter UserTimeline有效,但SearchTimeline似乎从未调用服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆