I guess someone else might know this better, but as a way forward I will just share what I think and it might help you forward on your problem.
I don't think it's that straight forward as a method returning a boolean
, since you by default do not have access to the users account. This is described on twitter4j homepage and I would assume you can follow the example described under Sign in with Twitter, if you are developing a web application.
If it's a native java application I guess you should go for the OAuth solution where you register your application at the twitter API (To get consumer key/secret) and grant access to validate users.
Basically I think you will end up having the user interact with the twitter login page like seen in the example from twitter4j:
// The factory instance is re-useable and thread safe.
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (null == accessToken) {
System.out.println("Open the following URL and grant access to your account:");
System.out.println(requestToken.getAuthorizationURL());
System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
String pin = br.readLine();
try{
if(pin.length() > 0){
accessToken = twitter.getOAuthAccessToken(requestToken, pin);
}else{
accessToken = twitter.getOAuthAccessToken();
}
} catch (TwitterException te) {
if(401 == te.getStatusCode()){
System.out.println("Unable to get the access token.");
}else{
te.printStackTrace();
}
}
}
YOu have some additional information in this Q: Twitter4J Only Authenticates With Me
Note that you need Twitter4J
version >=3.0 in order to get the API 1.1 support.
Hope it helps your forward.