2013-04-18 96 views
4

我是新來的社交網絡分析和Twitter API.I想收集關於某個話題的鳴叫。所以我寫了下面的代碼Twitter的認證證書

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(); 

      } 
     } 
    } 
} 

但是當我運行下面的程序如下錯誤啓動未來

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) 

我在哪裏需要提供的憑證在我的計劃

感謝

回答