1
votes

Hi I am trying to update a twitter status using the following code but I keep getting the following exception, TwitterException{exceptionCode=[bfb606ed-4ef9708b bfb606ed-4ef97061], statusCode=-1, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}

I have put in the correct consumer "key" and consumer "secret", any help is appreciated!

    public void twitterUpdates(String update) throws TwitterException, IOException  {
    // The factory instance is re-useable and thread safe.
    Twitter twitter = TwitterFactory.getSingleton();
    twitter.setOAuthConsumer("key", "secret");
    RequestToken requestToken = twitter.getOAuthRequestToken();
    AccessToken accessToken = loadAccessToken(twitter.verifyCredentials().getId());
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (accessToken == null) {
        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 available) 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();
            }
        }
    }
    // persist to the accessToken for future reference.
    storeAccessToken(twitter.verifyCredentials().getId(), accessToken);
    Status status = twitter.updateStatus(update);
    System.out.println("Successfully updated the status to ["
            + status.getText() + "].");


     System.exit(0);
}
3

3 Answers

1
votes

I got this same exception and it was coming from the call RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL); Turned out to be a proxy related issue. Fixed it by setting the proxy host and port in the ConfigurationBuilder:

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey(key);
cb.setOAuthConsumerSecret(secret);
cb.setHttpProxyHost("proxy");
cb.setHttpProxyPort(8080);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();

Note that I'm also passing callbackURL to the getOAuthRequestToken method:

RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL);
0
votes

In my personal experience with this problem, it was the firewall that was causing the issue and no problem with the coding - I did not work in solving the firewall issue. Hope this helps some people!

0
votes

you need to increment the timeout.

$cb->setConnectionTimeout(20000); $cb->setTimeout(50000);