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