java - 如何使用 twitter4j 库执行 "near"搜索推文?

标签 java twitter twitter4j

我正在尝试执行“附近”搜索查询,以使用

获取靠近特定位置的推文

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/

相关文章:

python - 如何在条形图中从一列列表中绘制词频

android - 如何在Android中的AsyncTask中保存变量

java - Twitter4J 转发一条消息

java - 如何获取以毫秒为单位的 UTC 日期?

java - 在@Before 之外使用@InjectMocks

java - 进行排列后,如何将它们添加到数组中? [ java ]

ios - 如何使用 ID 在 Twitter 中的好友墙上发布消息

java - Twitter4j:在主题标签中搜索关键字

java - 缺少 Twitter4j 身份验证凭据

java - 为什么我的 Guava 缓存不断覆盖项目?