Oauth problem

oauth
twitter4j

#1

i am facing problem in get authentication from twitter with java GUI

My program is sample. button to request for authentication code it open browser and give you the code the user have to copy that code and past it in jtextfield and write a message and the recipient than click on another button to send the message my problem in send button I am getting (Unable to get the access token.)

I hope some one help me.

button to get authentication code

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("7VxxxxxRG", "Jh74xxxxxxxNzTtuFV");
RequestToken requestToken = null;
try {
    requestToken = twitter.getOAuthRequestToken();
    //jf.setText(requestToken.getToken());
} catch (TwitterException ex) {
    Logger.getLogger(TwitterSK.class.getName()).log(Level.SEVERE, null, ex);
}
try {
    Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL()));
} catch (IOException | URISyntaxException ex) {
    Logger.getLogger(TwitterSK.class.getName()).log(Level.SEVERE, null, ex);
}

button to send the message (here’s the problem)

Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer("7VsxxxxxeWtxRG", "Jh74xxxxxx9NzTtuFV");
RequestToken requestToken = null;
AccessToken accessToken = null;
try {
    requestToken = twitter.getOAuthRequestToken();
} catch (TwitterException ex) {
    Logger.getLogger(TwitterSK.class.getName()).log(Level.SEVERE, null, ex);
}

String pin = null;
pin = pin_tx.getText();
try {
    if (pin.length() > 0)
    {
        accessToken = twitter.getOAuthAccessToken(requestToken, pin);
        storeAccessToken(twitter.verifyCredentials(), accessToken);
        twitter.sendDirectMessage(Tuser.getText(),keyP2.getText());
    }  
} catch (TwitterException te) {
    System.out.println("Unable to get the access token.");
}

#2

Would be great if you could edit your post and mark code blocks properly (either use fenced code blocks if you are familiar with markdown, or select the code and click the </> button in the editor), that makes it much easier to read and understand your code! Thanks!