social networking - Twitter authentication credentials -
i new social network analysis , twitter api.i wanted collect tweets on topic .so have written following code
package com; import java.io.bufferedwriter; import java.io.file; import java.io.filewriter; import java.io.ioexception; import java.util.list; import twitter4j.query; import twitter4j.queryresult; import twitter4j.status; import twitter4j.tweet; import twitter4j.twitter; import twitter4j.twitterexception; import twitter4j.twitterfactory; public class twittersearchadvance { public static void main(string[] vishal) throws twitterexception, ioexception { // list<tweet> data = new arraylist<tweet>(); stringbuffer stringbuffer = new stringbuffer(); twitter twitter = new twitterfactory().getinstance(); (int page = 0; page <= 4; page++) { query query = new query("airtel"); // query.setrpp(100); // 100 results per page queryresult qr = twitter.search(query); list<status> qrtweets = qr.gettweets(); system.out.println("-------------------" + qrtweets.size()); // break out if there no more tweets (status t : qrtweets) { system.out.println(t.getcreatedat() + ": " + t.gettext()); stringbuffer.append(t); stringbuffer.append("\n"); bufferedwriter bw = new bufferedwriter(new filewriter(new file( "/home/vishal/firstdocu.txt"), true)); bw.write(stringbuffer.tostring()); bw.newline(); // bw.write(t.getcreatedat() + ": " + t.gettext()); bw.close(); } } } }
but when run following program following error starts coming
exception in thread "main" java.lang.illegalstateexception: authentication credentials missing. see http://twitter4j.org/configuration.html detail. @ twitter4j.twitterbaseimpl.ensureauthorizationenabled(twitterbaseimpl.java:200) @ twitter4j.twitterimpl.get(twitterimpl.java:1833) @ twitter4j.twitterimpl.search(twitterimpl.java:282) @ com.twittersearchadvance.main(twittersearchadvance.java:28)
where need provide credentials in program
thanks
have @ options here http://twitter4j.org/en/configuration.html
there number of ways provide credentials program:
- properties file
- configurationbuilder class
- system properties
- environment variables
all details , instructions can found in link
Comments
Post a Comment