private boolean authorize() {

        //Request token to be sent to Twitter
        RequestToken requestToken;

        try {

            //set Twitter variables
            twitter.setOAuthConsumer(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);

            //get request token and set accesstoken to null
            requestToken = twitter.getOAuthRequestToken();
            accessToken = null;

            //get the url to call
            String authURL = requestToken.getAuthorizationURL(); //get the URL
            try {
                new OpenURL(authURL); //open the URL in a browser
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "Dialog",
                        JOptionPane.ERROR_MESSAGE);
                System.exit(1);
            }

            //while we don't have a valid access token, keep trying to get one
            while (accessToken == null) {

                try {

                    if (authPin != null) { //if we have a pin try to get an access token
                        accessToken = twitter.getOAuthAccessToken(requestToken, authPin);
                        twitter.setOAuthAccessToken(accessToken);

                        return true;

                    } else { //no pin = get one from the user
                        if (pinForm == null) {
                            getPin(authURL);
                        } else { //if they've closed the pin form reopen it
                            pinForm.setVisible(true);
                        }
                    }

                } catch (TwitterException te) {
                    if (401 == te.getStatusCode()) { //twitter is down
                        JOptionPane.showMessageDialog(new JFrame(), "Unable to get the access token. Twitter is down", "Dialog",
                                JOptionPane.ERROR_MESSAGE);
                        pinForm = null;
                        authPin = null;
                    } else {
                        JOptionPane.showMessageDialog(new JFrame(), te.getErrorMessage(), "Dialog",
                                JOptionPane.ERROR_MESSAGE);
                        return false;
                    }
                }
            }
        } catch (TwitterException ex) { //twitter is down
            JOptionPane.showMessageDialog(new JFrame(), ex.getMessage(), "Dialog",
                    JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
        return false;
    }