位置跟踪项必须以逗号分隔的形式给出 lat/longs Twitter4J Scala

Location track items must be given as pairs of comma separated lat/longs Twitter4J Scala

我正在尝试按用户位置过滤推文。为此,我在 Scala 中使用 Twitter4J。但是每次我得到一个错误

Parameter not accepted with the role. 406:Returned by the Search API when an invalid format is specified in the request.
Returned by the Streaming API when one or more of the parameters are not suitable for the resource. The track parameter, for example, would throw this error if:
The track keyword is too long or too short.
The bounding box specified is invalid.
No predicates defined for filtered resource, for example, neither track nor follow parameter defined.
Follow userid cannot be read.
Location track items must be given as pairs of comma separated lat/longs: [Ljava.lang.String;@48d1de0f

这是我的代码:

def main(args: Array[String]): Unit = {    
    val twitterStream = TwitterStreamFilters.configureTwitterStream()
        val counter = new Counter
        twitterStream.addListener(counter)
        TwitterStreamFilters.filterTwitterStreamByLocation(twitterStream, Array(-122.75,36.8,-121.75,37.8))
        TwitterStreamFilters.closeTwitterStream(twitterStream)
    }

我从 this link 获取了旧金山的位置。 那么为什么这个推特流不起作用?如有任何建议,我将不胜感激。

定位方法:

  def filterTwitterStreamByLocation(twitterStream: TwitterStream, coordinates: Array[Double]) = {
    twitterStream.filter(new FilterQuery().locations(coordinates))
  }

所以按照我上面的评论,这应该可以解决您的问题:

def main(args: Array[String]): Unit = {    
    val twitterStream = TwitterStreamFilters.configureTwitterStream()
        val counter = new Counter
        twitterStream.addListener(counter)
        TwitterStreamFilters.filterTwitterStreamByLocation(twitterStream, Array(Array(-122.75,36.8,-121.75,37.8)))
        TwitterStreamFilters.closeTwitterStream(twitterStream)
    }

def filterTwitterStreamByLocation(twitterStream: TwitterStream, coordinates: Array[Array[Double]]) = {
    twitterStream.filter(new FilterQuery().locations(coordinates))
  }