55import java .util .Scanner ;
66import java .util .concurrent .ExecutionException ;
77
8- import com .github .scribejava .apis .WunderlistAPI20 ;
8+ import com .github .scribejava .apis .WunderlistAPI ;
99import com .github .scribejava .core .builder .ServiceBuilder ;
1010import com .github .scribejava .core .model .OAuth2AccessToken ;
1111import com .github .scribejava .core .model .OAuthRequest ;
1212import com .github .scribejava .core .model .Response ;
1313import com .github .scribejava .core .model .Verb ;
1414import com .github .scribejava .core .oauth .OAuth20Service ;
1515
16- public class Wunderlist20Example {
16+ public class WunderlistExample {
1717
1818 private static final String NETWORK_NAME = "Wunderlist" ;
1919 private static final String PROTECTED_RESOURCE_URL = "https://a.wunderlist.com/api/v1/user" ;
2020
21- private Wunderlist20Example () {
21+ private WunderlistExample () {
2222 }
2323
2424 public static void main (String ... args ) throws IOException , InterruptedException , ExecutionException {
2525 // Replace these with your own values
26- final String apiKey = "your_api_key " ;
27- final String apiSecret = "your_api_secret " ;
26+ final String apiKey = "apiKey " ;
27+ final String apiSecret = "apiSecret " ;
2828 final String callbackUrl = "http://example.com/callback" ;
29- final String secretState = "security_token" + new Random ().nextInt (999_999 );
30-
29+ final String secretState = "security_token" + new Random ().nextInt (999_999 );
30+
3131 final OAuth20Service service = new ServiceBuilder (apiKey )
3232 .apiSecret (apiSecret )
3333 .callback (callbackUrl )
3434 .state (secretState )
3535 .debug ()
36- .build (WunderlistAPI20 .instance ());
37- final Scanner in = new Scanner (System .in , "UTF-8" );
38-
39- System .out .println ("=== " + NETWORK_NAME + "'s OAuth Workflow ===" );
40- System .out .println ();
41-
36+ .build (WunderlistAPI .instance ());
4237
43- // Obtain the Authorization URL
44- System .out .println ("Fetching the Authorization URL..." );
45- final String authorizationUrl = service .getAuthorizationUrl ();
46- System .out .println ("Got the Authorization URL!" );
47- System .out .println ("Now go and authorize ScribeJava here:" );
48- System .out .println (authorizationUrl );
49- System .out .println ("And paste the authorization code here" );
50- System .out .print (">>" );
51- final String code = in .nextLine ();
52- in .close ();
38+ final String code ;
39+ try (Scanner in = new Scanner (System .in , "UTF-8" )) {
40+ System .out .println ("=== " + NETWORK_NAME + "'s OAuth Workflow ===" );
41+ System .out .println ();
42+ // Obtain the Authorization URL
43+ System .out .println ("Fetching the Authorization URL..." );
44+ final String authorizationUrl = service .getAuthorizationUrl ();
45+ System .out .println ("Got the Authorization URL!" );
46+ System .out .println ("Now go and authorize ScribeJava here:" );
47+ System .out .println (authorizationUrl );
48+ System .out .println ("And paste the authorization code here" );
49+ System .out .print (">>" );
50+ code = in .nextLine ();
51+ }
5352 System .out .println ();
5453
5554 // Trade the Request Token and Verifier for the Access Token
@@ -62,7 +61,6 @@ public static void main(String... args) throws IOException, InterruptedException
6261 // Now let's go and ask for a protected resource!
6362 System .out .println ("Now we're going to access a protected resource..." );
6463 final OAuthRequest request = new OAuthRequest (Verb .GET , PROTECTED_RESOURCE_URL );
65- request .addHeader ("X-Client-ID" , apiKey );
6664 service .signRequest (accessToken , request );
6765 final Response response = service .execute (request );
6866 System .out .println ("Got it! Lets see what we found..." );
0 commit comments