Twitter Authentication Credentials

I am new to social network analysis and twitter API. I wanted to collect tweets on a specific topic. So I wrote the 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(); for (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 are no more tweets for (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 I run the following program, the next error starts

 Exception in thread "main" java.lang.IllegalStateException: Authentication credentials are missing. See http://twitter4j.org/configuration.html for the detail. at twitter4j.TwitterBaseImpl.ensureAuthorizationEnabled(TwitterBaseImpl.java:200) at twitter4j.TwitterImpl.get(TwitterImpl.java:1833) at twitter4j.TwitterImpl.search(TwitterImpl.java:282) at com.TwitterSearchAdvance.main(TwitterSearchAdvance.java:28) 

Where do I need to provide credentials in my program

thanks

+4
source share
1 answer

Check out the options here http://twitter4j.org/en/configuration.html

There are several ways to provide credentials to your program:

  • Properties file
  • Class ConfigurationBuilder
  • Properties of the system
  • Environment Variables

All information and instructions can be found in the link

+6
source

All Articles