Search code examples
twitter4j

Twitter4j - Bad Authentication data. code - 215


I am newbie with Twitter4J API. I am looking to validate my access, but I can't.

public class Buscador { 
public static void main(String [] args) throws TwitterException{

    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("avantis_bc");
    QueryResult result = twitter.search(query);

    do{

              List<Status> tweets = result.getTweets();

              for(Status tweet: tweets){
                   System.out.println("Usuário: "+tweet.getUser().getScreenName() + " Tweet: "+tweet.getText());
              }

              query = result.nextQuery();

              if(query!=null)
                   result = twitter.search(query);
    }while(query!=null);
}   

}

Exception in thread "main" 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=506c3b98 or

http://www.google.co.jp/search?q=10b457b8

TwitterException{exceptionCode=[506c3b98-10b457b8], statusCode=400, message=Bad

Authentication data., code=215, retryAfter=-1, rateLimitStatus=null, version=4.0.3}

at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:163)

at twitter4j.HttpClientBase.request(HttpClientBase.java:53)

at twitter4j.HttpClientBase.get(HttpClientBase.java:71)

at twitter4j.TwitterImpl.get(TwitterImpl.java:1562)

at twitter4j.TwitterImpl.search(TwitterImpl.java:253)

at Buscador.main(Buscador.java:54)

Solution

  • I just check the code and it works, the output is Usuário: bullshitbuffetx Tweet: one time me n quade went to avantis and i wore my braid hoodie n he had on a braid shirt, he zipped up his jacket bc he was so embarassed
    You should review your OAuth, maybe you put it wrong.
    Remember that you need to make your application on Twitter and then use your credentials.