import java.net.URLEncoder; import org.scribe.builder.ServiceBuilder; import org.scribe.builder.api.LinkedInApi; import org.scribe.model.OAuthRequest; import org.scribe.model.Response; import org.scribe.model.Token; import org.scribe.model.Verb; import org.scribe.oauth.OAuthService; // TODO changes these to your API key and secret String companyid = context.get("companyid"); //Get your own API key and OAuth tokens from your LinkedIn developer account String API_KEY = "xxxxxx"; String API_SECRET = "xxxxxx"; String oauth_Token = "xxxxxx"; String oauth_TokenPassword = "xxxxxxx"; String API_URL = "http://api.linkedin.com/v1/companies/" + companyid + ":(id,name,ticker,description,email-domains,company-type,employee-count-range)"; // This is the url for the exchange of a token from OAuth2.0 to OAuth1.0a String EXCHANGE_URL = "https://api.linkedin.com/uas/oauth/accessToken"; // Once you parse out the Access Token you can use it here // API : "http://developer.linkedin.com/apis" // http://api.linkedin.com/v1/companies/79129:(id,name,ticker,description,email-domains,company-type,employee-count-range,location try { OAuthService oauthservice= new ServiceBuilder().provider(LinkedInApi.class).apiKey(API_KEY).apiSecret(API_SECRET).build(); try { oauth_Token = URLEncoder.encode(oauth_Token, "UTF-8"); } catch (Exception e) { System.out.println("YOU MAY BE IN TROUBLE BUT IT STILL MIGHT WORK"); } // since we are just making a two-legged call we don't need a member // token to sign the token exchange request // because we are only identifying an app and not the member // Token token = new Token("",""); OAuthRequest request = new OAuthRequest(Verb.POST, EXCHANGE_URL + "?xoauth_oauth2_access_token=" + oauth_Token); // service.signRequest(token, request); Response response = request.send(); System.out.println("This should be our new OAuth token in here: " + response.getBody()); /* * Some code you write to parse our the new token and secret */ // TODO change these to the right value Token oauth1_0aToken = new Token(oauth_Token, oauth_TokenPassword); request = new OAuthRequest(Verb.GET, API_URL); oauthservice.signRequest(oauth1_0aToken, request); response = request.send(); // System.out.println("HEADER************"+response.getHeaders().toString()); // ADEPTIA gets the default stream name which can be configured in the process flow service.write((response.getBody().toString()).getBytes(),"default"); } catch (Exception e) { // TODO: handle exception }