private void requestBearerToken() throws IOException
  {
    // Do the OAUTH2 Authenticate
    String oAuthTokenUrl = "https://api.twitter.com/oauth2/token";
    URL tokenURL = new URL(oAuthTokenUrl);

    HttpsURLConnection con = (HttpsURLConnection) tokenURL.openConnection();
    con.setDoOutput(true);
    con.setDoInput(true);
    con.setRequestMethod("POST");
    con.setRequestProperty("Host", "api.twitter.com");
    con.setRequestProperty("Authorization", "Basic " + encodeKeys(oAuthCredentials));
    con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
    con.setUseCaches(false);

    writeRequest(con, "grant_type=client_credentials");

    // Parse the JSON response into a JSON mapped object to fetch fields from.
   JSONObject obj = (JSONObject) JSONValue.parse(readResponse(con));

    if (obj == null)
      throw new IOException("Bearer token request failed.");  //TODO: add to ResourceBundle
    else
    {
      String tokenType = (String) obj.get("token_type");
      String accessToken = (String) obj.get("access_token");

      if(tokenType.equals("bearer") && (accessToken != null))
      {
        twitterBearerToken = new TwitterBearerToken();
        twitterBearerToken.setTokenType(tokenType);
        twitterBearerToken.setAccessToken(accessToken);

        controller.appendStatus("token_type: " + twitterBearerToken.getTokenType());      //TODO: add to ResourceBundle
        controller.appendStatus("access_token: " + twitterBearerToken.getAccessToken());  //TODO: add to ResourceBundle
      }
    }
    con.disconnect();
  }