1+ package org .scribe .examples ;
2+
3+ import java .util .Scanner ;
4+
5+ import org .scribe .builder .*;
6+ import org .scribe .builder .api .*;
7+ import org .scribe .model .*;
8+ import org .scribe .model .Request .*;
9+ import org .scribe .oauth .*;
10+
11+ public class FoursquareExample
12+ {
13+ private static final String AUTHORIZE_URL = "http://foursquare.com/oauth/authorize?oauth_token=" ;
14+ private static final String PROTECTED_RESOURCE_URL = "http://api.foursquare.com/v1/user" ;
15+
16+ public static void main (String [] args )
17+ {
18+ OAuthService service = new ServiceBuilder ()
19+ .provider (FoursquareApi .class )
20+ .apiKey ("FEGFXJUFANVVDHVSNUAMUKTTXCP1AJQD53E33XKJ44YP1S4I" )
21+ .apiSecret ("AYWKUL5SWPNC0CTQ202QXRUG2NLZYXMRA34ZSDW4AUYBG2RC" )
22+ .build ();
23+ Scanner in = new Scanner (System .in );
24+
25+ System .out .println ("=== Foursquare's OAuth Workflow ===" );
26+ System .out .println ();
27+
28+ // Obtain the Request Token
29+ System .out .println ("Fetching the Request Token..." );
30+ Token requestToken = service .getRequestToken ();
31+ System .out .println ("Got the Request Token!" );
32+ System .out .println ();
33+
34+ System .out .println ("Now go and authorize Scribe here:" );
35+ System .out .println (AUTHORIZE_URL + requestToken .getToken ());
36+ System .out .println ("And paste the verifier 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 .GET , PROTECTED_RESOURCE_URL );
51+ service .signRequest (accessToken , request );
52+ 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 Scribe! :)" );
59+ }
60+
61+ }
0 commit comments