OAuthService service = new ServiceBuilder() .provider(TwitterApi.class) .apiKey("your_api_key") .apiSecret("your_api_secret") .build(); ... Token requestToken = service.getRequestToken(); String your_token = requestToken.getToken(); ... Verifier verifier = new Verifier("your_previously_retrieved_verifier"); Token accessToken = service.getAccessToken(requestToken, verifier);
public InputStream getImageAsStream(String urlStr) { OAuthRequest request = new OAuthRequest(Verb.GET, urlStr); oAuthService.signRequest(accessToken, request); final Response response = request.send(); return response.getStream(); }
public OAuthServiceDecorator(OAuthService oAuthService, String type) { super(); this.oAuthService = oAuthService; this.oAuthType = type; this.authorizationUrl = oAuthService.getAuthorizationUrl(null); }
@Override protected Void doInBackground(String... params) { System.out.println("001 OauthEnd doInBackground-->" + params[0]); String url = params[0]; if (url.contains("user_refused")) { setResult(RESULT_CANCELED); finish(); } else { final Uri uri = Uri.parse(url); final String verifier = uri.getQueryParameter("oauth_verifier"); final Verifier v = new Verifier(verifier); System.out.println("hp Verifier>>>> " + v.getValue()); final Token accessToken = oas_linkedin.getAccessToken(requestToken, v); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); oas_linkedin.signRequest(accessToken, request); Response response = request.send(); // TODO JSON response in intent RESPONSE Intent intent = new Intent(); intent.putExtra("RESPONSE", response.getBody()); setResult(RESULT_OK, intent); finish(); } return null; } }
OAuthService service = new ServiceBuilder() .provider(TradeKingAPI.class) .signatureType(QueryString) .apiKey("My consumer key") .apiSecret("My secret") .scope("API.Public") .build(); Token requestToken = service.getRequestToken(); //make your API calls OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.viagogo.net/Public/Event/235"); service.signRequest(requestToken, request); Response response = request.send(); System.out.println(response.getBody());
@Override protected WebView doInBackground(Void... params) { System.out.println("001 OauthStart doInBackground"); oas_linkedin = new ServiceBuilder().provider(LinkedInApi.class) .apiKey(APIKEY).apiSecret(APISECRET) .callback(OAUTH_CALLBACK_URL).build(); requestToken = oas_linkedin.getRequestToken(); authURL = oas_linkedin.getAuthorizationUrl(requestToken); return (WebView) findViewById(R.id.web_view); }
service = new OAuth10aServiceImpl(api, oauthConfig); } else { DefaultApi20 api = new DefaultApi20() { service = new OAuth20ServiceImpl(api, oauthConfig);
/** * {@inheritDoc} */ public Token getRequestToken(int timeout, TimeUnit unit) { return getRequestToken(new TimeoutTuner(timeout, unit)); }
/** * {@inheritDoc} */ public Token getAccessToken(Token requestToken, Verifier verifier, int timeout, TimeUnit unit) { return getAccessToken(requestToken, verifier, new TimeoutTuner(timeout, unit)); }
/** * {@inheritDoc} */ public OAuthService createService(OAuthConfig config) { return new OAuth20ServiceImpl(this, config); }
/** * Returns the {@link OAuthService} for this Api * * @param apiKey Key * @param apiSecret Api Secret * @param callback OAuth callback (either URL or 'oob') * @param scope OAuth scope (optional) */ public OAuthService createService(OAuthConfig config) { return new OAuth10aServiceImpl(this, config); } }
@Override protected Void doInBackground(String... params) { System.out.println("001 OauthEnd doInBackground-->" + params[0]); String url = params[0]; if (url.contains("user_refused")) { setResult(RESULT_CANCELED); finish(); } else { final Uri uri = Uri.parse(url); final String verifier = uri.getQueryParameter("oauth_verifier"); final Verifier v = new Verifier(verifier); System.out.println("hp Verifier>>>> " + v.getValue()); final Token accessToken = oas_linkedin.getAccessToken(requestToken, v); final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL); oas_linkedin.signRequest(accessToken, request); Response response = request.send(); // TODO JSON response in intent RESPONSE Intent intent = new Intent(); intent.putExtra("RESPONSE", response.getBody()); setResult(RESULT_OK, intent); finish(); } return null; } }
private <T> SmugMugResponse<T> makeRequest( String url, TypeReference<SmugMugResponse<T>> typeReference) throws IOException { // Note: there are no request params that need to go here, because smugmug fully specifies // which resource to get in the URL of a request, without using query params. String fullUrl; if (!url.contains("https://")) { fullUrl = BASE_URL + url; } else { fullUrl = url; } OAuthRequest request = new OAuthRequest(Verb.GET, fullUrl + "?_accept=application%2Fjson"); oAuthService.signRequest(accessToken, request); final Response response = request.send(); if (response.getCode() < 200 || response.getCode() >= 300) { throw new IOException( String.format("Error occurred in request for %s : %s", url, response.getMessage())); } String result = response.getBody(); return mapper.readValue(result, typeReference); }
OAuthService service = new ServiceBuilder() .provider(TradeKingAPI.class) .signatureType(QueryString) .apiKey("My consumer key") .apiSecret("My secret") .scope("API.Public") .build(); Token requestToken = service.getRequestToken(); //make your API calls OAuthRequest request = new OAuthRequest(Verb.GET, "http://api.viagogo.net/Public/Event/235"); service.signRequest(requestToken, request); Response response = request.send(); System.out.println(response.getBody());
@Override protected WebView doInBackground(Void... params) { System.out.println("001 OauthStart doInBackground"); oas_linkedin = new ServiceBuilder().provider(LinkedInApi.class) .apiKey(APIKEY).apiSecret(APISECRET) .callback(OAUTH_CALLBACK_URL).build(); requestToken = oas_linkedin.getRequestToken(); authURL = oas_linkedin.getAuthorizationUrl(requestToken); return (WebView) findViewById(R.id.web_view); }
public String createAuthorizationUrl(Token requestToken) { String url = mOAuthService.getAuthorizationUrl(requestToken); if (mSupportAppLinkedNotebooks) { url += "&supportLinkedSandbox=true"; } return url; }
oAuthService.signRequest(accessToken, request);
private void sign(OAuthRequest request) { if (token != null) { service.signRequest(token, request); } }
@Override public void signRequest(Token accessToken, OAuthRequest request) { wrapped.signRequest(accessToken, request); }
public void process(HttpRequest request, HttpContext ctx) throws HttpException, IOException { try { HttpHost host = (HttpHost) ctx.getAttribute(ExecutionContext.HTTP_TARGET_HOST); final URI requestURI = new URI(host.toURI()).resolve(request.getRequestLine().getUri()); Verb verb = Verb.valueOf(request.getRequestLine().getMethod().toUpperCase()); OAuthRequest oauthRequest = new OAuthRequest(verb, requestURI.toString()); this.service = getOauthService(isOAuth1); service.signRequest(token, oauthRequest); if (signature == OAuthSignature.HEADER) { //If signature is to be added as header for (Map.Entry<String, String> entry : oauthRequest.getHeaders().entrySet()) { request.setHeader(entry.getKey(), entry.getValue()); } } else { //If signature is to be added as query param URI uri = new URI(oauthRequest.getCompleteUrl()); ((RequestWrapper) request).setURI(uri); } } catch (URISyntaxException ex) { throw new HttpException("Error rebuilding request URI", ex); } }