仅使用地理位置处理twitter4j查询 [英] Processing twitter4j query with only Geolocation

查看:151
本文介绍了仅使用地理位置处理twitter4j查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定。每次我们只收到100条推文。我想根据地理位置在地图上显示它们。有什么方法可以获得100条推文,它们都具有地理位置。因为现在只有三四分之一的地理位置。

Ok. Each time we get only 100 tweets. I want to show them on a map based on the Geolocation. Is there any way I can get 100 tweets that all of them have Geolocation. Because now only 3-4 out of 100 has Geolocation.

我用FilterQuery阅读了一些例子,但Processing却向我抛出一个错误,就像未知。 b $ b

I read some examples with FilterQuery but Processing throws me an error on it, as unknown.

推荐答案

这里是一个工作示例。这是使用twitter4j 4.0.2测试的

Here is an working example. This was tested using twitter4j 4.0.2

接口StatusListener是你可以用你的推文进行任何操作的地方类型...是否它们到达

The interface StatusListener is where you can do whatever you want with your tweets Kind of... is there that they arrive

使用流API:
$ b

Using stream API:

import twitter4j.util.*;
import twitter4j.*;
import twitter4j.management.*;
import twitter4j.api.*;
import twitter4j.conf.*;
import twitter4j.json.*;
import twitter4j.auth.*;


TwitterStream twitterStream;


double[][] boundingBox= {
  {
    -180, -90
  }
  , {
    180, 90
  }
}; /// whole world;

void setup() {     
  size(100, 100);    
  background(0); 
  openTwitterStream();
}  


void draw() {     
  background(0);
}  



// Stream it
void openTwitterStream() {  

  ConfigurationBuilder cb = new ConfigurationBuilder();
  cb.setOAuthConsumerKey(FILL_IN);
  cb.setOAuthConsumerSecret(FILL_IN);
  cb.setOAuthAccessToken(FILL_IN);
  cb.setOAuthAccessTokenSecret(FILL_IN);


  TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
  twitterStream.addListener(listener);

  FilterQuery filter = new FilterQuery();
  filter.locations(boundingBox);


  twitterStream.filter(filter);

  println("connected");
} 


// Implementing StatusListener interface
StatusListener listener = new StatusListener() {

  //@Override
  public void onStatus(Status status) {
    GeoLocation loc = status.getGeoLocation();
    System.out.println("@" + status.getUser().getScreenName() + " - " + loc);
  }

  //@Override
  public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
    System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
  }

  //@Override
  public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
    System.out.println("Got track limitation notice:" + numberOfLimitedStatuses);
  }

  //@Override
  public void onScrubGeo(long userId, long upToStatusId) {
    System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
  }

  //@Override
  public void onStallWarning(StallWarning warning) {
    System.out.println("Got stall warning:" + warning);
  }

  //@Override
  public void onException(Exception ex) {
    ex.printStackTrace();
  }
};

这篇关于仅使用地理位置处理twitter4j查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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