/** {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier) { OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); switch (api.getAccessTokenVerb()) { case POST: request.addBodyParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addBodyParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addBodyParameter(OAuthConstants.CODE, verifier.getValue()); request.addBodyParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) { request.addBodyParameter(OAuthConstants.SCOPE, config.getScope()); } if (config.hasGrantType()) { request.addBodyParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); } break; case GET: default: request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) { request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope()); } if (config.hasGrantType()) { request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, config.getGrantType()); } } Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier) { OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addQuerystringParameter(OAuthConstants.GRANT_TYPE, OAuthConstants.AUTHORIZATION_CODE); request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope()); Response response = request.send(); return api.getAccessTokenExtractor().extract(response.getBody()); }
/** {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier) { OAuthRequest request = new OAuthRequest(api.getAccessTokenVerb(), api.getAccessTokenEndpoint()); request.addQuerystringParameter(OAuthConstants.CLIENT_ID, config.getApiKey()); request.addQuerystringParameter(OAuthConstants.CLIENT_SECRET, config.getApiSecret()); request.addQuerystringParameter(OAuthConstants.CODE, verifier.getValue()); request.addQuerystringParameter(OAuthConstants.REDIRECT_URI, config.getCallback()); if (config.hasScope()) request.addQuerystringParameter(OAuthConstants.SCOPE, config.getScope()); System.out.println("Access Token request is:" + request); Response response = request.send(); System.out.println("Got the Access Token!"); System.out.println("(if your curious here's the response: " + response.getBody() + " )"); return api.getAccessTokenExtractor().extract(response.getBody()); }