if(Global.TOKEN_AUTHORIZED != null) { OAuthRequest request = new OAuthRequest(Verb.POST, url); request.addHeader("Content-Type", "application/json"); request.addPayload(params[0]); Global.OAUTH_SERVICE.signRequest(Global.TOKEN_AUTHORIZED, request); response = request.send(); }
OAuthRequest r = new OAuthRequest(Verb.POST, url); ByteArrayOutputStream out = new ByteArrayOutputStream(); toSend.writeTo(out); r.addPayload(out.toByteArray()); r.addHeader(toSend.getContentType().getName(), toSend.getContentType().getValue()); OAuth10aServiceImpl oauth = (OAuth10aServiceImpl)client._oauth; OAuthRequest sr = new OAuthRequest(Verb.GET, serviceProvider); oauth.signRequest(client._oauthToken, sr); r.addHeader("X-Auth-Service-Provider",serviceProvider); String oauthHeader = sr.getHeaders().get("Authorization"); r.addHeader("X-Verify-Credentials-Authorization", oauthHeader);
final OAuth20Service service = util.getService(); final OAuthRequest request = new OAuthRequest(Verb.POST, url, service); request.addHeader("Content-Type", "application/json;charset=UTF-8"); request.addPayload(MAPPER.writeValueAsString(requestModel)); // or this if you have a json string // request.addPayload(json); service.signRequest(new OAuth2AccessToken(accessToken), request); final Response postResponse = request.send();
public static String shortenUrl(String longUrl) { @SuppressWarnings("unused") OAuthService oAuthService = new ServiceBuilder().provider(GoogleApi.class).apiKey("anonymous").apiSecret("anonymous") .scope("https://www.googleapis.com/auth/urlshortener") .build(); OAuthRequest oAuthRequest = new OAuthRequest(Verb.POST, "https://www.googleapis.com/urlshortener/v1/url"); oAuthRequest.addHeader("Content-Type", "application/json"); String json = "{\"longUrl\": \"http://"+longUrl+"/\"}"; oAuthRequest.addPayload(json); Response response = oAuthRequest.send(); Type typeOfMap = new TypeToken<Map<String, String>>() {}.getType(); Map<String, String> responseMap = new GsonBuilder().create().fromJson(response.getBody(), typeOfMap); String st=responseMap.get("id"); return st; }
private void postToLinkedin(String comment) { SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(LinkedinDialogActivity.this); String token = prefs.getString(Constants.LINKEDIN_TOKEN, ""); String secret = prefs.getString(Constants.LINKEDIN_TOKEN_SECRET, ""); Token accessToken = new Token(token, secret); OAuthService service = new ServiceBuilder().provider(LinkedInApi.class) .apiKey(Constants.CONSUMER_KEY) .apiSecret(Constants.CONSUMER_SECRET) .callback(Constants.OAUTH_CALLBACK_URL).build(); String url = "http://api.linkedin.com/v1/people/~/shares"; OAuthRequest request = new OAuthRequest(Verb.POST, url); String payLoad = "<?xml version='1.0' encoding='UTF-8'?><share><comment>Check out the Sep 13 Second share!</comment><content><title>My new share with linked-in</title><description>Leverage the Share API to maximize engagement on user-generated content on LinkedIn</description><submitted-url>https://developer.linkedin.com/documents/share-api</submitted-url><submitted-image-url>http://m3.licdn.com/media/p/3/000/124/1a6/089a29a.png</submitted-image-url></content><visibility><code>anyone</code></visibility></share>"; request.addHeader("Content-Length", Integer.toString(payLoad.length())); request.addHeader("Content-Type", "text/xml"); request.addPayload(payLoad); service.signRequest(accessToken, request); Response response = request.send(); System.out.println("response >>>> " + response.getBody()); }
final OAuthRequest request = new OAuthRequest(Verb.POST, PROTECTED_RESOURCE_URL + "/user/repos", service); request.addHeader("content-type", "application/json"); request.addPayload(jsonInString);
/* You will have done this bit earlier to authorize the user OAuthService service = new ServiceBuilder().provider(TwitterApi.SSL.class).apiKey("[YOUR API KEY]").apiSecret("[YOUR SECRET]").callback("twitter://callback").build(); Token accessToken = Do you oauth authorization as normal */ OAuthRequest request = new OAuthRequest(Verb.POST, "https://upload.twitter.com/1/statuses/update_with_media.json"); MultipartEntity entity = new MultipartEntity(); try { entity.addPart("status", new StringBody("insert vacuous statement here")); entity.addPart("media", new FileBody(new File("/path/of/your/image/file"))); ByteArrayOutputStream out = new ByteArrayOutputStream(); entity.writeTo(out); request.addPayload(out.toByteArray()); request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue()); service.signRequest(accessToken, request); Response response = request.send(); if (response.isSuccessful()) { // you're all good } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
entity.writeTo(out); request.addPayload(out.toByteArray()); request.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());
ByteArrayOutputStream out = new ByteArrayOutputStream(); entity.writeTo(out); req.addPayload(out.toByteArray()); req.addBodyParameter("status", "I have uploaded test image on twitter"); req.addHeader(entity.getContentType().getName(), entity.getContentType().getValue());