Hello everyone, I’m trying to get tweets based on keyword, I’m accessing “/1.1/statuses/filter.json” through Twitter4j.
However, the eclipse say unauthorized access. I doubled checked the credential and I’m sure about it.
I tried to test the OAuth tool, and I tried the cURL command and it worked fine! Also, tried the sudo ntpdate ntp.ubuntu.com and still facing the problem.
what could cause this problem?
This is the Code:
import twitter4j.FilterQuery;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.User;
import twitter4j.conf.ConfigurationBuilder;
import twitter4j.StallWarning;
public class SimpleStream {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("");
cb.setOAuthConsumerSecret("");
cb.setOAuthAccessToken("");
cb.setOAuthAccessTokenSecret("");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener() {
@Override
public void onException(Exception arg0) {
// TODO Auto-generated method stub
}
@Override
public void onDeletionNotice(StatusDeletionNotice arg0) {
// TODO Auto-generated method stub
}
@Override
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
@Override
public void onStatus(Status status) {
User user = status.getUser();
// gets Username
String username = status.getUser().getScreenName();
System.out.println(username);
String profileLocation = user.getLocation();
System.out.println(profileLocation);
long tweetId = status.getId();
System.out.println(tweetId);
String content = status.getText();
System.out.println(content +"\n");
}
@Override
public void onTrackLimitationNotice(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onStallWarning(StallWarning arg0) {
}
};
FilterQuery fq = new FilterQuery();
String keywords[] = {"ireland"};
fq.track(keywords);
twitterStream.addListener(listener);
twitterStream.filter(fq);
}
}
The problem:
[Thu Apr 21 00:38:38 AST 2016]Establishing connection.
[Thu Apr 21 00:38:43 AST 2016]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.
<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/filter.json'. Reason:
<pre> Unauthorized</pre>
</body>
</html>