java - Twitter4j : Search -
i use twitter4j status hashtag :
configurationbuilder cb = new configurationbuilder(); cb.setdebugenabled(true) .setoauthconsumerkey("*******") .setoauthconsumersecret("****") .setoauthaccesstoken("*****") .setoauthaccesstokensecret("*****"); twitterfactory tf = new twitterfactory(cb.build()); twitter twitter = tf.getinstance(); query query = new query("source:twitter4j yusukey"); queryresult result; try { result = twitter.search(query); (status status : result.gettweets()) { system.out.println("@" + status.getuser().getscreenname() + ":" + status.gettext()); } } catch (twitterexception e) { // todo auto-generated catch block e.printstacktrace(); }
i replaced * keys , application unable start
java.lang.runtimeexception: unable start activity componentinfo{com.example.app_evnt/com.example.app_evnt.socialnetwork}: android.os.networkonmainthreadexception
all networkcalls not allowed on main thread, can try in thread:
configurationbuilder cb = new configurationbuilder(); cb.setdebugenabled(true) .setoauthconsumerkey("*******") .setoauthconsumersecret("****") .setoauthaccesstoken("*****") .setoauthaccesstokensecret("*****"); twitterfactory tf = new twitterfactory(cb.build()); final twitter twitter = tf.getinstance(); query query = new query("source:twitter4j yusukey"); new thread(new runnable() { @override public void run() { try { queryresult result = twitter.search(query); (status status : result.gettweets()) { system.out.println("@" + status.getuser().getscreenname() + ":" + status.gettext()); } } catch (twitterexception e) { // todo auto-generated catch block e.printstacktrace(); } } }).start();
Comments
Post a Comment