{"id":8766,"date":"2012-09-25T23:41:48","date_gmt":"2012-09-25T18:11:48","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=8766"},"modified":"2012-09-26T00:18:45","modified_gmt":"2012-09-25T18:48:45","slug":"search-twitter-users-using-twitter4j","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/search-twitter-users-using-twitter4j\/","title":{"rendered":"Search Twitter Users using Twitter4j"},"content":{"rendered":"<p>Hi,<\/p>\n<p>In the previous <a href=\"http:\/\/www.tothenew.com\/blog\/searching-tweets-on-twitter-using-twitter4j\/\">blog<\/a> we saw how to fetch tweets based on some search criteria using the Twitter4j, a java wrapper library available for Twitter API calls.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p>In the same grails project, i had the requirement to search users based of their name or words. Twitter4j library provides a cool way to search users over twitter with its searchUsers() method. It helped me a lot to make quick search of users on twitter.<\/p>\n<pre>\r\n\r\n\r\n<\/pre>\n<p>Twitter User search API needs to have twitter account <strong>access_token<\/strong> and <strong>access_secret<\/strong>, which we obtains after authorizing\/connecting twitter account with the application as mentioned in this <a href=\"http:\/\/www.tothenew.com\/blog\/integrating-java-application-with-twitter\/\">blog<\/a>.<\/p>\n<pre>\r\n\r\n<\/pre>\n<p><strong>Code to search Users:-<\/strong><\/p>\n<p>[java]<\/p>\n<p>           String queryString=&#8217;Vishal&#8217; \/\/ some name which you want to search on twitter<br \/>\n           TwitterFactory factory = new TwitterFactory()<br \/>\n           Twitter twitter = factory.getInstance()<br \/>\n           twitter.setOAuthConsumer(consumerKey, consumerSecret)<br \/>\n           AccessToken accessToken = new AccessToken(twitterToken, twitterSecret)<br \/>\n           twitter.setOAuthAccessToken(accessToken)<\/p>\n<p>           List users = twitter.searchUsers(queryString, 1)<br \/>\n            users.each { user-&gt;<br \/>\n                   println(&quot;Name: ${user.screenName}&quot;)<br \/>\n                   println(&quot;Location: ${user.location}&quot;)<br \/>\n                  }<br \/>\n[\/java]<\/p>\n<p>This code will fetch the latest 20 users which fits the searched criteria.<\/p>\n<p>Hope this helps.<\/p>\n<pre>\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Hi, In the previous blog we saw how to fetch tweets based on some search criteria using the Twitter4j, a java wrapper library available for Twitter API calls. In the same grails project, i had the requirement to search users based of their name or words. Twitter4j library provides a cool way to search users [&hellip;]<\/p>\n","protected":false},"author":19,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[700,873,1018,1022,1023,1046,1019],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8766"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/19"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=8766"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/8766\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=8766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=8766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=8766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}