Java Reference
In-Depth Information
GenericUrl url = new GenericUrl(API_ENDPOINT_URL);
HttpRequest req = factory.buildGetRequest(url);
HttpResponse resp = req.execute();
System.out.println(resp.getStatusCode());
System.out.println(resp.parseAsString());
}
}
Take some time to read through the code and the comments. Don't forget to fill in the keys you
received from Twitter in the CONSUMER_KEY and CONSUMER_SECRET variables. Note also the
REQUEST_TOKEN_URL , AUTHORIZE_URL , and ACCESS_TOKEN_URL variables, containing the OAuth
URLs provided to you earlier by Twitter.
Execute this code in Eclipse; you'll see the following output:
Request Token:
- oauth_token = QEaZwniqkgRcB25gAuGGQg7rHz48OR5a8uoZ3AJs
- oauth_token_secret = scnIHqN59V0WAe2nyEoxiOWRejcBA7WPmQv5Ah5Q
Go to the following link:
https://api.twitter.com/oauth/authenticate?oauth_token=
QEaZwniqkgRcB25gAuGGQg7rHz48OR5a8uoZ3AJs
Enter the verification PIN provided by Twitter:
(Your tokens will differ.) Open the given link in your web browser. A Twitter page will appear ask-
ing you if you want to allow access to an external application. See Figure 10-21.
Press Authorize App. Next, Twitter will provide you with a PIN that you'll need to provide to the
application. See Figure 10-22.
Go back to the running Eclipse console, enter the PIN, and press Enter. The program will resume
and execute the REST call:
Enter the verification PIN provided by Twitter:
2162766
Access Token:
- oauth_token = 9807092-pEFWjo4juyL3MhZ1IruqvUeq1bvbpb83ZcDGCBtVEB
- oauth_token_secret = QlG4enz5Zo4YKMXq6Pv4kgoLFH5x7cLBZpHsYshhNynwz
200
[*REALLY LONG JSON RESPONSE*]
Note If you had set a callback URL, Twitter would not provide a PIN but
would refer the user back to an URL you specify with the access token pro-
vided as an URL parameter, which your application can then intercept auto-
matically. Since setting up web servers with Java hasn't been covered yet, here
you can use the PINā€based approach.
Search WWH ::




Custom Search