Tuesday 15, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Saturday, 9 July 2016

LinkedIn OAuth 1.0a Example using Scribe Java

In this example we are going to see about how to use LinkedIn OAuth 1.0a using Scribe Java

LinkedIn OAuth 1.0a Example

LinkedInExample.java

01.import java.util.Scanner;
02.import com.github.scribejava.core.builder.ServiceBuilder;
03.import com.github.scribejava.apis.LinkedInApi;
04.import com.github.scribejava.core.model.OAuth1AccessToken;
05.import com.github.scribejava.core.model.OAuth1RequestToken;
06.import com.github.scribejava.core.model.OAuthRequest;
07.import com.github.scribejava.core.model.Response;
08.import com.github.scribejava.core.model.Verb;
09.import com.github.scribejava.core.oauth.OAuth10aService;
10.import java.io.IOException;
11. 
12.public abstract class LinkedInExample {
13. 
14.private static final String PROTECTED_RESOURCE_URL
16. 
17.public static void main(String... args) throws IOException {
18.final OAuth10aService service = new ServiceBuilder()
19..apiKey("your client id")
20..apiSecret("your client secret")
21..build(LinkedInApi.instance());
22.final Scanner in = new Scanner(System.in);
23. 
24.System.out.println("=== LinkedIn's OAuth Workflow ===");
25.System.out.println();
26. 
27.// Obtain the Request Token
28.System.out.println("Fetching the Request Token...");
29.final OAuth1RequestToken requestToken = service.getRequestToken();
30.System.out.println("Got the Request Token!");
31.System.out.println();
32. 
33.System.out.println("Now go and authorize ScribeJava here:");
34.System.out.println(service.getAuthorizationUrl(requestToken));
35.System.out.println("And paste the verifier here");
36.System.out.print(">>");
37.final String oauthVerifier = in.nextLine();
38.System.out.println();
39. 
40.// Trade the Request Token and Verfier for the Access Token
41.System.out.println("Trading the Request Token for an Access Token...");
42.final OAuth1AccessToken accessToken = service.getAccessToken(requestToken, oauthVerifier);
43.System.out.println("Got the Access Token!");
44.System.out.println("(if your curious it looks like this: " + accessToken
45.+ ", 'rawResponse'='" + accessToken.getRawResponse() + "')");
46.System.out.println();
47. 
48.// Now let's go and ask for a protected resource!
49.System.out.println("Now we're going to access a protected resource...");
50.final OAuthRequest request = new OAuthRequest(Verb.GET, PROTECTED_RESOURCE_URL, service);
51.service.signRequest(accessToken, request);
52.final Response response = request.send();
53.System.out.println("Got it! Lets see what we found...");
54.System.out.println();
55.System.out.println(response.getBody());
56. 
57.System.out.println();
58.System.out.println("Thats it man! Go and build something awesome with ScribeJava! :)");
59.}
60. 
61.}

Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer

Related Posts:

  • Foursquare OAuth 1.0a Example using Scribe JavaIn this example we are going to see about how to use Foursquare OAuth 1.0a using Scribe Java Foursquare OAuth 1.0a Example using Scribe FoursquareExample.java import java.util.Scanner; import com.github.scribejava.core.build… Read More
  • Digg OAuth 1.0a Example using Scribe JavaIn this example we are going to see about how to use Digg OAuth 1.0a using Scribe Java Digg OAuth 1.0a Example using Scribe DiggExample.java import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBuilder;… Read More
  • NeteaseWeibo OAuth 1.0a Example using Scribe JavaIn this example we are going to see about how to use NeteaseWeibo OAuth1.0a using Scribe Java NeteaseWeibo OAuth1.0a Example using Scribe NeteaseWeiboExample.java import java.util.Scanner; import com.github.scribejava.core.b… Read More
  • Trello OAuth 1.0a Example using Scribe JavaIn this example we are going to see about how to use Trello OAuth 1.0a using Scribe Java Trello OAuth 1.0a Example using Scribe TrelloExample.java import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBu… Read More
  • Tumblr OAuth 1.0a Example using Scribe JavaIn this example we are going to see about how to use Tumblr OAuth 1.0a using Scribe Java Tumblr OAuth 1.0a Example using Scribe TumblrExample.java import java.util.Scanner; import com.github.scribejava.core.builder.ServiceBu… Read More
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: LinkedIn OAuth 1.0a Example using Scribe Java Rating: 5 Reviewed By: eHowToNow