Monday 14, Apr 2025
We are moved to new domain
Click -> www.ehowtonow.com
Sunday, 17 July 2016

Live OAuth 2.0 Example using Scribe Java

In this example we are going to see about how to use Live OAuth2.0 using Scribe Java

Live OAuth2.0 Example using Scribe

LiveExample.java

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

Shop and help us

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

Related Posts:

  • 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
  • Imgur OAuth 2.0 Example using Scribe JavaIn this example we are going to see about how to use Imgur OAuth 2.0 using Scribe Java Imgur OAuth 2.0 Example ImgurExample.java import com.github.scribejava.apis.ImgurApi; import com.github.scribejava.core.builder.ServiceBu… Read More
  • Salesforce OAuth 2.0 Example using Scribe JavaIn this example we are going to see about how to use Salesforce OAuth 2.0 using Scribe Java Salesforce OAuth 2.0 Example SalesforceExample.java import java.io.IOException; import java.net.URLDecoder; import java.net.URLEncod… 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
  • 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
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Live OAuth 2.0 Example using Scribe Java Rating: 5 Reviewed By: eHowToNow