title: Java Twitter4j OAuth not working
body: <p>I am reading <a href="http://twitter4j.org/en/code-examples.html" rel="nofollow">these</a> Twitter4j examples. I am trying to get #7: OAuth support to work but I am having troubles. I have the following code:</p>
  
  <pre><code>try {
      Twitter twitter = TwitterFactory.getSingleton();
      twitter.setOAuthConsumer("VALID KEY FROM APP HERE", "VALID SECRET FROM APP HERE");
      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();
          if(pin.length() &gt; 0){
              accessToken = twitter.getOAuthAccessToken(requestToken, pin);
          } else {
              accessToken = twitter.getOAuthAccessToken();
          }
      }
      System.out.println(twitter.verifyCredentials().getId());
      System.out.println(accessToken);
  } catch(Exception e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>The output in my console is the following:</p>
  
  <pre><code>Open the following URL and grant access to your account:
  https://api.twitter.com/oauth/authorize?oauth_token=&lt;REMOVED&gt;
  Enter the PIN(if aviailable) or just hit enter.[PIN]:
  </code></pre>
  
  <p>When I copy the original link and go to the URL in my web browser it opens the expected Twitter app authorization page. When I grant it access it sends me to the app's callback (doesn't exist) as expected. I am never given a pin as described in my console, so I just press enter and the result is:</p>
  
  <pre><code>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.
  Error processing your OAuth request: Invalid oauth_verifier parameter
  
  Relevant discussions can be found on the Internet at:
          http://www.google.co.jp/search?q=17bf128c or
          http://www.google.co.jp/search?q=12b8f614
  TwitterException{exceptionCode=[17bf128c-12b8f614], statusCode=401, message=null
  , code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.4}
          at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
          at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
          at twitter4j.HttpClientBase.post(HttpClientBase.java:86)
          at twitter4j.auth.OAuthAuthorization.getOAuthAccessToken(OAuthAuthorizat
  ion.java:125)
          at twitter4j.TwitterBaseImpl.getOAuthAccessToken(TwitterBaseImpl.java:33
  6)
          at tweetserver.TweetServer.main(TweetServer.java:51)
  </code></pre>
  
  <p>I have checked my app's key and secret multiple times and copy/pasted them into my code. I have also used the same key/secret in a PHP application &amp; in Twitter4j with the access token and the access token secret (allows direct access to use the API on my account without needing permission) without any problems.</p>
  
  <p>I believe I am not understanding the example clearly, how could I fix this problem? Thank you for reading.</p>