Search twitter by language

余生长醉 提交于 2020-01-24 14:12:05

问题


In twitter by using lang operator you can search for retrieving tweets from a particular language: For example, the following search will return tweets only in english:

https://twitter.com/search?q=lang:en

Is there a way to achieve this using twitter api, especially using twitter4j. I know there is a language attribute for search but it also requires at least one keyword to make a search, I would like to search by a particular language without giving any keyword query. The following command in java driver returns the following error:

Query searchQuery = new Query() //
                        .count(resultsPerPage) //
                        .since(since)//
                        .lang("en");

400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Query parameters are missing
code - 25

Cheers


回答1:


You must pass the same do you use in the twitter search, your query will be like:

new Query("lang:en")



回答2:


Using twitter4j,

Query query = new Query(); query.setLang("en"); query.setQuery(searchQuery);



来源:https://stackoverflow.com/questions/14627437/search-twitter-by-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!