@Override public OAuth2Token getOAuth2Token() throws TwitterException { if (token != null) { throw new IllegalStateException("OAuth 2 Bearer Token is already available."); } HttpParameter[] params = new HttpParameter[conf.getOAuth2Scope() == null ? 1 : 2]; params[0] = new HttpParameter("grant_type", "client_credentials"); if (conf.getOAuth2Scope() != null) { params[1] = new HttpParameter("scope", conf.getOAuth2Scope()); } HttpResponse res = http.post(conf.getOAuth2TokenURL(), params, this, null); if (res.getStatusCode() != 200) { throw new TwitterException("Obtaining OAuth 2 Bearer Token failed.", res); } token = new OAuth2Token(res); return token; }