Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Twitter4j搜索API,基于位置和时间间隔的推文_Twitter_Twitter4j_Twitter Search - Fatal编程技术网

Twitter4j搜索API,基于位置和时间间隔的推文

Twitter4j搜索API,基于位置和时间间隔的推文,twitter,twitter4j,twitter-search,Twitter,Twitter4j,Twitter Search,我有一个特定的要求,我想收集所有的推根据以下参数 1我正在使用搜索API,例如我想搜索Iphone6 2区域方面,即如果我按照我得到结果的城市指定纬度和经度,那么当我指定印度的纬度和经度时,是否可以按照代码中的国家获取所有结果 它不起作用 3我应该每隔多长时间运行我的应用程序,以便获得最新更新的tweet,而不获取以前获取的tweet This is the code that I have written public final class twitterdate {

我有一个特定的要求,我想收集所有的推根据以下参数

1我正在使用搜索API,例如我想搜索Iphone6

2区域方面,即如果我按照我得到结果的城市指定纬度和经度,那么当我指定印度的纬度和经度时,是否可以按照代码中的国家获取所有结果 它不起作用

3我应该每隔多长时间运行我的应用程序,以便获得最新更新的tweet,而不获取以前获取的tweet

This is the code that I have written 


  public final class twitterdate {


    public static void main(String[] args)throws Exception {

        double res;
        double lat,lon;

        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
                .setOAuthConsumerKey("MyKEY")
                .setOAuthConsumerSecret("MySecret")
                .setOAuthAccessToken("MyAccesstoken")

                .setOAuthAccessTokenSecret("MyTokenSecret").setHttpConnectionTimeout(100000);




        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();

        lat=18.9750;  // THis works , but it doenst work when I specify latitude and longitude of India
        lon=72.8258;
        res=1;

        try {





           QueryResult result=twitter.search(new Query("iphone").since("2014-11-19").until("2014-11-22").geoCode(new GeoLocation(lat, lon), res,"1mi"));
           // Since and untill doesnt work as expected sometimes it fetches the date tweets specified on "since" method sometimes fetches the tweets specified on the date of until method
           // Also since and until doesnt work when i specify a time stamp.
           List<Status> qrTweets = result.getTweets();
              System.out.println("hi");

            for (Status tweet : qrTweets )  
            {   
                 System.out.println( tweet.getId() + " " + "@" + tweet.getUser().getScreenName()  + " : " + tweet.getText() + " :::" + tweet.getCreatedAt() );  
            }

        } catch (TwitterException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }


}
如果有人能帮我满足我的要求,我将不胜感激,因为我在谷歌上搜索了很多,但找不到任何合适的解决方案。
提前谢谢

您是否尝试过使用FilterQuery?下面的代码片段将为您提供连续的推文流。 据我所知,您希望从印度获取与iPhone 6相关内容的推文。 使用搜索查询,您可能会一次又一次地收到相同的推文集

你可以试试下面这样的方法,我不知道你用什么坐标从印度获取推特!,你必须做一些尝试和错误,微调你想要定位推特的坐标

    StatusListener listener = new StatusListener(){
        public void onStatus(Status status) {
            //if (status.getText().contains)
            if(status.getUser().getLang().equalsIgnoreCase("en")
                    || status.getUser().getLang().equalsIgnoreCase("en_US")) {
                System.out.println(status.getUser().getName() + " :: " + status.getText() + " :: " + status.getGeoLocation());
            }
        }
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
        public void onException(Exception ex) {
            ex.printStackTrace();
        }
        public void onScrubGeo(long arg0, long arg1) {

        }
        public void onStallWarning(StallWarning arg0) {

        }
    };

    ConfigurationBuilder config = new ConfigurationBuilder();
    config.setOAuthConsumerKey("");
    config.setOAuthConsumerSecret("");
    config.setOAuthAccessToken("");
    config.setOAuthAccessTokenSecret("");

    TwitterStream twitterStream = new TwitterStreamFactory(config.build()).getInstance();
    twitterStream.addListener(listener);
    FilterQuery query = new FilterQuery();
    // New Delhi India
    double lat = 28.6;
    double lon = 77.2;

    double lon1 = lon - .5;
    double lon2 = lon + .5;
    double lat1 = lat - .5;
    double lat2 = lat + .5;

    double box[][] = {{lon1, lat1}, {lon2, lat2}};

    query.locations(box);

    String[] trackArray = {"iphone"}; 
    query.track(trackArray);
    twitterStream.filter(query);
但是,FilterQuery有一个警告,即它使用位置或轨迹列表来获取数据。为了解决这个问题,您可以在onStatus方法中加入一个内容过滤器逻辑


希望这对您有所帮助。

Hi mbaxi,我成功地更正了项目设置,但在运行应用程序时,我收到了此错误-线程主java.lang.NoSuchMethodError中的异常:twitter4j.conf.Configuration.getRequestHeadersLjava/util/Map;有什么线索吗?嗨,看来罐子有一些兼容性问题,所以我使用了下面的罐子twitter4j-stream-3.0.5.jar和twitter4j-core-3.0.5.jar,它成功了:Thx又是你的救命稻草: