2015-09-24 68 views
0

我在嘗試使用twitter4J審覈twitter公開個人資料。
我試過twitter4j git位置的例子,但它沒有奏效。在java中獲取帖子形式的twitter公開個人資料

import java.util.ArrayList; 
import java.util.List; 

import twitter4j.Paging; 
import twitter4j.Status; 
import twitter4j.Twitter; 
import twitter4j.TwitterException; 
import twitter4j.TwitterFactory; 
import twitter4j.conf.ConfigurationBuilder; 

public class TwitterTimeLine { 
public static void main(String[] args) { 
    ConfigurationBuilder cb = new ConfigurationBuilder(); 
    cb.setOAuthConsumerKey(""); 
    cb.setOAuthConsumerSecret(""); 
    cb.setOAuthAccessToken(""); 
    cb.setOAuthAccessTokenSecret(""); 

    Twitter twitter = new TwitterFactory(cb.build()).getInstance(); 

    int pageno = 1; 
    String user = "google"; 
    List<Status> statuses = new ArrayList<Status>(); 

    while (true) { 

     try { 

     int size = statuses.size(); 
     Paging page = new Paging(pageno++, 100); 
     statuses.addAll(twitter.getUserTimeline(user, page)); 
     if (statuses.size() == size) 
      break; 
     } 
     catch(TwitterException e) { 

     e.printStackTrace(); 
     } 
    } 

    System.out.println("Total: "+statuses.size()); 
} 
} 

但它總是給我錯誤

400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response. 
message - Bad Authentication data. 
code - 215 

Relevant discussions can be found on the Internet at: 
    http://www.google.co.jp/search?q=4be80492 or 
    http://www.google.co.jp/search?q=0a6306df 
TwitterException{exceptionCode=[4be80492-0a6306df], statusCode=400, message=Bad Authentication data., code=215, retryAfter=-1, rateLimitStatus=null, version=4.0.4} 
    at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164) 
    at twitter4j.HttpClientBase.request(HttpClientBase.java:57) 
    at twitter4j.HttpClientBase.get(HttpClientBase.java:75) 
    at twitter4j.TwitterImpl.get(TwitterImpl.java:1786) 
    at twitter4j.TwitterImpl.getUserTimeline(TwitterImpl.java:131) 
    at com.twitter.ibeat.iBeatTwitter.TwitterTimeLine.main(TwitterTimeLine.java:33) 
400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response. 
message - Bad Authentication data. 
code - 215 

能否請你幫我得到這個工作。
問候
Virendra瓦爾

+0

Twitter API 1.1中的所有方法都需要通過OAuth進行身份驗證。看看http://stackoverflow.com/questions/17143985/twitter-api-error-215 –

+0

感謝@BalwinderSingh我創建了OAuth令牌,它工作。你能告訴他們我今天只能使用相同的代碼如何得到鳴叫嗎?此外,我需要在這裏獲得多個用戶的推文,所以你可以請建議我更改代碼。 – viren

回答

0

問題是使用OAuth令牌和查詢API從twitter4J解決。

相關問題