Twitter4J check credentials and trap

I have the following code in google appengine to check if twitter credentials are valid using twitter4j

public void doGet(HttpServletRequest req, HttpServletResponse resp) {
    String Test = "Testing Twitter4J";
    try {

        ConfigurationBuilder confbuilder  = new ConfigurationBuilder();
        confbuilder.setOAuthAccessToken("A") 
        .setOAuthAccessTokenSecret("B") 
        .setOAuthConsumerKey("C") 
        .setOAuthConsumerSecret("D"); 
        Twitter twitter = new TwitterFactory(confbuilder.build()).getInstance(); 

        //Status status = twitter.updateStatus("Working lunch today");
        User user = twitter.verifyCredentials();
        Test = "Successfully updated the status to [" + user.getScreenName() + "].";

    } catch (TwitterException e) {
        Test =  "no";
    }
    try {
        resp.getOutputStream().write(Test.getBytes());
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return;
}

If the credentials are valid, they work as expected. If I cancel access, so the credentials are invalid, I get an error when creating the application:

Uncaught exception from servlet
twitter4j.TwitterRuntimeException: 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.
message - Invalid or expired token
code - 89

Relevant discussions can be found on the Internet at:
    http://www.google.co.jp/search?q=93f2523c or
    http://www.google.co.jp/search?q=8b74a4e3
TwitterException{exceptionCode=[93f2523c-8b74a4e3], statusCode=401, message=Invalid or expired token, code=89, retryAfter=-1, rateLimitStatus=null, version=3.0.3}

from "User user = twitter.verifyCredentials ();" line. I was expecting a TwitterException to be thrown from javadoc at: http://twitter4j.org/javadoc/twitter4j/api/UsersResources.html#verifyCredentials () but it looks like I'm getting a TwitterRuntimeException. What for? I cannot find TwitterRuntimeException exception notes in javadocs.

+5
source
1

:

, URL . URL , .

+1

All Articles