1
votes

It's the first time for me using twitter4j i got project from github trying to run it to see the result of how using twitter4j and when i run the Crawler class i got this

0 [Twitter Stream consumer-1[initializing]] INFO twitter4j.TwitterStreamImpl - Establishing 
  connection. 5617 [Twitter Stream consumer-1[Establishing connection]] INFO 
  twitter4j.TwitterStreamImpl - 401:Authentication credentials (https://dev.twitter.com/pages
  /auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access 
  token/secret, and the system clock is in sync.

i guess from Ensure that you have set valid consumer key/secret that i should change the proprieties of twitter4j.proprieties !!? am i right or false ? and how can i change the proprieties of it ? Can someone help ?

2
After creation of app you will get consumer key/secret which you can configure in your program using configurationbuilder. - prathap
Thanks for replying and help . i didn't see consumer key/secret but i have APP key/secret what's the difference between APP and consumer ? and what is configuration builder ? - user3928141

2 Answers

-1
votes

I got the similar error with using twitter4j 3.0.x version. I solved it by updating twitter4j to the 4.0.0 version

-2
votes

Try the following options given in this link to set the Keys:

  1. via twitter4j.properties: Save a standard properties file named "twitter4j.properties". Place it to either the current directory, root of the classpath directory.

debug=true oauth.consumerKey=********************* oauth.consumerSecret=****************************************** oauth.accessToken=************************************************** oauth.accessTokenSecret=******************************************

  1. via ConfigurationBuilder: You can use ConfigurationBuilder class to configure Twitter4J programatically as follows:

ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true)
.setOAuthConsumerKey("*********************")
.setOAuthConsumerSecret("******************************************") .setOAuthAccessToken("**************************************************") .setOAuthAccessTokenSecret("******************************************"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance();

  1. via System Properties: You can configure Twitter4J via System properties. Note that you need "twitter4j." prefix.

$ java -Dtwitter4j.debug=true -Dtwitter4j.oauth.consumerKey=********************* -Dtwitter4j.oauth.consumerSecret=****************************************** -Dtwitter4j.oauth.accessToken=************************************************** -Dtwitter4j.oauth.accessTokenSecret=****************************************** -cp twitter4j-core-4.0.2.jar:yourApp.jar yourpackage.Main

  1. via environment variables: Note that you need "twitter4j." prefix.

$ export twitter4j.debug=true $ export twitter4j.oauth.consumerKey=********************* $ export twitter4j.oauth.consumerSecret=****************************************** $ export twitter4j.oauth.accessToken=************************************************** $ export twitter4j.oauth.accessTokenSecret=****************************************** $ java -cp twitter4j-core-4.0.2.jar:yourApp.jar yourpackage.Main