我正在尝试执行“附近”搜索查询,以使用
获取靠近特定位置的推文twitter4j 但出现异常。
public static void main(String[] args) {
Twitter twitter = new TwitterFactory().getInstance();
try {
String searchTerm = "jobs near:\"san francisco\"";
QueryResult result = twitter.search(new Query(searchTerm));
List<Tweet> tweets = result.getTweets();
for (Tweet tweet : tweets) {
System.out.println("@" + tweet.getFromUser() + " - " + tweet.getText());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to search tweets: " + te.getMessage());
}
}
我遇到的异常
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following). {"error":"Invalid parameter"} Relevant discussions can be on the Internet at: http://www.google.co.jp/search?q=d35baff5 or http://www.google.co.jp/search?q=08c3b248 TwitterException{exceptionCode=[d35baff5-08c3b248], statusCode=403, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.5}Failed to search tweets: 403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following). {"error":"Invalid parameter"}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:185)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:65)
at twitter4j.internal.http.HttpClientWrapper.get(HttpClientWrapper.java:85)
at twitter4j.TwitterImpl.get(TwitterImpl.java:1895)
at twitter4j.TwitterImpl.search(TwitterImpl.java:98)
at com.xebia.lightning.scheduler.JobTweetsArchiver.main(JobTweetsArchiver.java:115)
最佳答案
See here :“near 运算符不能用于搜索查询。请改用地理编码参数”。
因此,将地理编码参数传递给搜索:
Returns tweets by users located within a given radius of the given latitude/longitude. The location is preferentially taking from the Geotagging API, but will fall back to their Twitter profile. The parameter value is specified by "latitude,longitude,radius", where radius units must be specified as either "mi" (miles) or "km" (kilometers). Note that you cannot use the near operator via the API to geocode arbitrary locations; however you can use this geocode parameter to search near geocodes directly.
关于java - 如何使用 twitter4j 库执行 "near"搜索推文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8022726/