【问题标题】:twitter4j 3.0.5 searching problemstwitter4j 3.0.5 搜索问题
【发布时间】:2013-10-13 23:44:42
【问题描述】:

大家好,我正在开发一个 java 桌面应用程序。我必须使用 twitter4j 3.0.5 按主题标签搜索推文。我对身份验证和搜索推文没有任何问题,但有一些问题: 我用 topsy.com 测试了我的搜索结果,我发现我收到的推文很少或没有推文。像#jobbingfest 有大约 500 条推文,但我发现它是空的...... 有趣的事情:Twitter.search(query) 文档说

Returns tweets that match a specified query. This method calls http://search.twitter.com/search.json

那个 api 返回一个像这样的 json

{"errors": [{"message": "The Twitter REST API v1 is no longer active. Please migrate to API v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]}

我有点困惑……如果该资源不再可用,为什么我还能收到推文?

我试图理解这个问题,但没办法......我不得不在这里写信寻求帮助:p。

非常感谢! 利西奥。

ps。对不起,也许我的英语不太好......

pps。检索我用来执行此操作的 100 多条推文是否正确?

List<MioStatus> listaStatus = null;
try {
    listaStatus = new ArrayList<MioStatus>();
    result = twitter.search(query);
    while(result.nextQuery() != null){
        for (Status status : result.getTweets()) {
            if(status.isRetweet()){
                listaStatus.add(new MioStatus(status.getId(), true, "RT " + status.getRetweetedStatus().getText(), status.getUser(), status.getGeoLocation(), status.getRetweetCount(), status.getCreatedAt()));
            }else{
                listaStatus.add(new MioStatus(status.getId(), true, status.getText(), status.getUser(), status.getGeoLocation(), status.getRetweetCount(), status.getCreatedAt()));
            }
         }
         result = twitter.search(result.nextQuery());
    }

【问题讨论】:

标签: java desktop-application twitter4j


【解决方案1】:

Twitter REST API v1 不再有效。您无法使用它来获取高音扬声器的数据。 From the site:

REST API 版本 1 现已弃用并将停止运行 在接下来的几个月里。立即迁移到 1.1 版。

不过,API 1.1 supports JSON only,放弃了对 XML、Atom 和 RSS 的支持。

再次在您的代码中,您在以下片段中调用nextQuery() 两次(阅读 cmets):

    while(result.nextQuery() != null){   // you are calling nextQuery() but 
                                   //you should call hasNext() boolean check
        for (Status status : result.getTweets()) {
            // do whatever you were doing

         }
         result = twitter.search(result.nextQuery()); 
                    // you are calling nextQuery() here, so no need to call 
                  //in while conditional check
       } // while ends here

【讨论】:

  • 是的,你是对的!但是:1) twitter4j 与 api 1.1 兼容 2) 我在获取推文时没有问题 - 完全没有。
  • 哦……太好了!没见过 hasNext()... -.- thnx
  • mmmm 搜索获取推文我发现了这个brightplanet.com/2013/06/… ...也许问题出在搜索 api 中。我必须使用流 api。我试试……
【解决方案2】:

好的,我得到了一些东西......就像那样改变了 twitter 的分配

Twitter twitter = TwitterFactory.getSingleton();

不要问我为什么,我使用的是 mvc,在地图中保存实例应该是一样的,但是...... 现在的问题是……“旧推文在哪里??”设置 setSince() 是没用的。推特限制?

【讨论】:

    猜你喜欢
    • 2018-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-13
    • 2015-08-10
    • 2011-09-12
    • 2011-06-10
    • 2018-05-08
    相关资源
    最近更新 更多