Reputation: 1197
It seems to be a never ending story, but I cant get access to Twitter from Twitter4J stream API.
I get an Exception from Twitter
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("xxxxxxxxxx");
cb.setOAuthConsumerSecret("xxxxxxxxxxx");
cb.setOAuthAccessToken("xxxxxxxxxxxxx");
cb.setOAuthAccessTokenSecret("xxxxxxxxxxxx");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListnerImpl statusListenerImpl = new StatusListnerImpl();
twitterStream.addListener(statusListenerImpl);
twitterStream.sample();
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.
Please help.
Upvotes: 1
Views: 100
Reputation: 51
For cleaness and simplicity I would recommend creating a separate file under project_name/resources/twitter4j.properties with contents:
debug=true
##Get the following from https://dev.twitter.com/
oauth.consumerKey=XXX
oauth.consumerSecret=XXX
oauth.accessToken=XXX
oauth.accessTokenSecret=XXX
Then you can create a new TwitterStream object as simple as:
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
Just make sure the properties file is available at compile time. Since you are using maven add the code below in pom.xml file (in build section):
<resources>
<resource>
<directory>${basedir}/resources</directory>
</resource>
</resources>
PS: you might want to hide your application specific keys/tokens
Upvotes: 1