Created
April 8, 2010 15:17
-
-
Save fernandezpablo85/360173 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import java.io.*; | |
import java.net.*; | |
import oauth.signpost.*; | |
import oauth.signpost.basic.*; | |
public class SingpostTest { | |
public static void main (String[] args) throws Exception, RuntimeException{ | |
OAuthConsumer consumer = new DefaultOAuthConsumer("CiEgwWDkA5BFpNrc0RfGyVuSlOh4tig5kOTZ9q97qcXNrFl7zqk-Ts7DqRGaKDCV","dhho4dfoCmiQXrkw4yslork5XWLFnPSuMR-8gscPVjY4jqFFHPYWJKgpFl4uLTM6"); | |
OAuthProvider provider = new DefaultOAuthProvider("https://api.linkedin.com/uas/oauth/request_token", | |
"https://api.linkedin.com/uas/oauth/access_token", | |
"https://api.linkedin.com/uas/oauth/authorize"); | |
System.out.println("Fetching request token from LinkedIn..."); | |
// we do not support callbacks, thus pass OOB | |
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND); | |
System.out.println("Request token: " + consumer.getToken()); | |
System.out.println("Token secret: " + consumer.getTokenSecret()); | |
System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization"); | |
System.out.println("Enter the PIN code and hit ENTER when you're done:"); | |
BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); | |
String pin = br.readLine(); | |
System.out.println("Fetching access token from LinkedIn..."); | |
provider.retrieveAccessToken(consumer, pin); | |
System.out.println("Access token: " + consumer.getToken()); | |
System.out.println("Token secret: " + consumer.getTokenSecret()); | |
URL url = new URL("http://api.linkedin.com/v1/people/~/network?count=50"); | |
HttpURLConnection request = (HttpURLConnection) url.openConnection(); | |
consumer.sign(request); | |
System.out.println("Sending request to LinkedIn..."); | |
request.connect(); | |
System.out.println("Response: " + request.getResponseCode() + " " | |
+ request.getResponseMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment