/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, null); }
/** * Get a fresh request token from the service provider. * * @param accessor * should contain a consumer that contains a non-null consumerKey * and consumerSecret. Also, * accessor.consumer.serviceProvider.requestTokenURL should be * the URL (determined by the service provider) for getting a * request token. * @param httpMethod * typically OAuthMessage.POST or OAuthMessage.GET, or null to * use the default method. * @throws OAuthProblemException * the HTTP response status code was not 200 (OK) */ public void getRequestToken(OAuthAccessor accessor, String httpMethod) throws IOException, OAuthException, URISyntaxException { getRequestToken(accessor, httpMethod, null); }
OAuthClient oAuthClient = new OAuthClient(new HttpClient4()); try { oAuthClient.getRequestToken(accessor); } catch (IOException e) { e.printStackTrace(); } catch (OAuthException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }
/** * Applies for a request token from the service provider. * * @return the request token. */ private String getAndStoreRequestToken() { // Get the request token. try { oauthClient.getRequestToken(accessor); } catch (IOException e) { LOG.severe("Could not reach service provider to get request token: " + e); } catch (OAuthException e) { LOG.severe("Unable to fetch request token. Authentication error: " + e); } catch (URISyntaxException e) { LOG.severe("Unable to fetch request token. Invalid url: " + e); } // Store request token in Datastore via a tokenData object. String requestToken = accessor.requestToken; storeUserProfile(new OAuthUser(userRecordKey, requestToken)); return accessor.requestToken; }