1+ package org .scribe .examples ;
2+
3+ import java .util .Scanner ;
4+
5+ import org .scribe .builder .ServiceBuilder ;
6+ import org .scribe .builder .api .DiggApi ;
7+ import org .scribe .model .*;
8+ import org .scribe .oauth .OAuthService ;
9+
10+ public class DiggExample {
11+ private static final String NETWORK_NAME = "Digg" ;
12+ private static final String PROTECTED_RESOURCE_URL = "http://services.digg.com/2.0/comment.digg" ;
13+
14+ public static void main (String [] args ) {
15+ // Replace these with your own api key and secret
16+ String apiKey = "myKey" ;
17+ String apiSecret = "mySecret" ;
18+ OAuthService service = new ServiceBuilder ().provider (DiggApi .class ).apiKey (apiKey ).apiSecret (apiSecret ).build ();
19+ Scanner in = new Scanner (System .in );
20+
21+ System .out .println ("=== " + NETWORK_NAME + "'s OAuth Workflow ===" );
22+ System .out .println ();
23+
24+ // Obtain the Request Token
25+ System .out .println ("Fetching the Request Token..." );
26+ Token requestToken = service .getRequestToken ();
27+ System .out .println ("Got the Request Token!" );
28+ System .out .println ();
29+
30+ // Obtain the Authorization URL
31+ System .out .println ("Fetching the Authorization URL..." );
32+ String authorizationUrl = service .getAuthorizationUrl (requestToken );
33+ System .out .println ("Got the Authorization URL!" );
34+ System .out .println ("Now go and authorize Scribe here:" );
35+ System .out .println (authorizationUrl );
36+ System .out .println ("And paste the authorization code here" );
37+ System .out .print (">>" );
38+ Verifier verifier = new Verifier (in .nextLine ());
39+ System .out .println ();
40+
41+ // Trade the Request Token and Verfier for the Access Token
42+ System .out .println ("Trading the Request Token for an Access Token..." );
43+ Token accessToken = service .getAccessToken (requestToken , verifier );
44+ System .out .println ("Got the Access Token!" );
45+ System .out .println ("(if your curious it looks like this: " + accessToken + " )" );
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+ OAuthRequest request = new OAuthRequest (Verb .POST , PROTECTED_RESOURCE_URL );
51+ request .addBodyParameter ("comment_id" , "20100729223726:4fef610331ee46a3b5cbd740bf71313e" );
52+ service .signRequest (accessToken , request );
53+ Response response = request .send ();
54+ System .out .println ("Got it! Lets see what we found..." );
55+ System .out .println ();
56+ System .out .println (response .getCode ());
57+ System .out .println (response .getBody ());
58+
59+ System .out .println ();
60+ System .out .println ("Thats it man! Go and build something awesome with Scribe! :)" );
61+
62+ }
63+ }
0 commit comments