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 FacebookExample
11+ {
12+ private static final String NETWORK_NAME = "Facebook" ;
13+ private static final String PROTECTED_RESOURCE_URL = "https://graph.facebook.com/me" ;
14+ private static final String NO_SECRET_NEEDED = "" ;
15+ private static final Token EMPTY_TOKEN = null ;
16+
17+ public static void main (String [] args )
18+ {
19+ OAuthService service = new ServiceBuilder ()
20+ .provider (FacebookApi .class )
21+ .apiKey ("anonymous" )
22+ .apiSecret ("anonymous" )
23+ .callback ("http://www.example.com/oauth_callback/" )
24+ .build ();
25+ Scanner in = new Scanner (System .in );
26+
27+ System .out .println ("=== " + NETWORK_NAME + "'s OAuth Workflow ===" );
28+ System .out .println ();
29+
30+ // Obtain the Authorization URL
31+ System .out .println ("Fetching the Authorization URL..." );
32+ String authorizationUrl = service .getAuthorizationUrl (EMPTY_TOKEN );
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 access token here" );
37+ System .out .print (">>" );
38+ Token accessToken = new Token (in .nextLine (), NO_SECRET_NEEDED );
39+ System .out .println ();
40+
41+ // Now let's go and ask for a protected resource!
42+ System .out .println ("Now we're going to access a protected resource..." );
43+ OAuthRequest request = new OAuthRequest (Verb .GET , PROTECTED_RESOURCE_URL );
44+ service .signRequest (accessToken , request );
45+ Response response = request .send ();
46+ System .out .println ("Got it! Lets see what we found..." );
47+ System .out .println ();
48+ System .out .println (response .getCode ());
49+ System .out .println (response .getBody ());
50+
51+ System .out .println ();
52+ System .out .println ("Thats it man! Go and build something awesome with Scribe! :)" );
53+
54+ }
55+ }
0 commit comments