wad'n dad'n deliciousJ

Java API for the social bookmarking service Delicious
deliciousJ uses the HTTP-based interface of the social bookmarking service Delicious. All functionality of the HTTP-based interface is made available as a Java API.
Note: The current version of deliciousJ needs to be updated to the new Delicious.
Download the latest version (0.7) of deliciousJ from the project SourceForge.net page.
Using Maven most of the dependencies will be downloaded automatically. Only
need to be downloaded and installed into the Maven repository manually.
Download commons-0.2-SNAPSHOT.jar from deliciousJ SourceForge.net page.
Deploy commons-0.2-SNAPSHOT.jar to your Maven repository:
> mvn deploy:deploy-file -DgroupId=de.wadndadn -DartifactId=commons -Dversion=0.2-SNAPSHOT -Dpackaging=jar -Dfile=commons-0.2-SNAPSHOT.jar -Durl=file:///<path to repository>
Download signpost-core-1.2.1.1.jar from Signpost downloads page.
Deploy signpost-core-1.2.1.1.jar to your Maven repository:
> mvn deploy:deploy-file -DgroupId=oauth.signpost -DartifactId=signpost-core -Dversion=1.2.1.1 -Dpackaging=jar -Dfile=signpost-core-1.2.1.1.jar -Durl=file:///<path to repository>
Download signpost-commonshttp4-1.2.1.1.jar from Signpost downloads page.
Deploy signpost-commonshttp4-1.2.1.1.jar to your Maven repository:
> mvn deploy:deploy-file -DgroupId=oauth.signpost -DartifactId=signpost-commonshttp4 -Dversion=1.2.1.1 -Dpackaging=jar -Dfile=signpost-commonshttp4-1.2.1.1.jar -Durl=file:///<path to repository>
These simple examples show the differences between authentication with
Only the few highlighted statements are different.
// Create credentials (Login on Delicious.com) UsernamePasswordCredentials deliciousCredentials = new UsernamePasswordCredentialsImpl(username, password); // Create an api configuration (/v1) // There are other createApiConfiguration methods that take additional parameters to configure a proxy (if necessary) ApiConfiguration apiConfiguration = ApiConfigurationImpl.createV1ApiConfiguration(deliciousCredentials); // Create an api factory ApiFactory apiFactory = ApiFactoryImpl.createApiFactory(apiConfiguration); // Create the Update api // Other apis to create are Posts, Tag bundles, Tags UpdateApi updateApi = apiFactory.createUpdateApi(); // Call update Update update = updateApi.update();
This example assumes that Consumer Key and Consumer Secret (from Yahoo! Developer Network that is the OAuth service provider for Delicious) are already known and that this consumer is already authenticated (Access Token and Token Secret are known). How authentication with OAuth works is shown in the next example.
// Create credentials (OAuth with Yahoo! ID) OAuthAuthenticatedCredentials oAuthCredentials = new OAuthAuthenticatedCredentialsImpl(consumerKey, consumerSecret, accessToken, tokenSecret); // Create an api configuration (/v2) // There are other createApiConfiguration methods that take additional parameters to configure a proxy (if necessary) ApiConfiguration apiConfiguration = ApiConfigurationImpl.createV2ApiConfiguration(oAuthCredentials); // Create an api factory ApiFactory apiFactory = ApiFactoryImpl.createApiFactory(apiConfiguration); // Create the Update api // Other apis to create are Posts, Tag bundles, Tags UpdateApi updateApi = apiFactory.createUpdateApi(); // Call update Update update = updateApi.update();
This example assumes that Consumer Key and Consumer Secret (from Yahoo! Developer Network that is the OAuth service provider for Delicious) are already known.
OAuthAuthenticationCredentials oAuthCredentials = new OAuthAuthenticationCredentialsImpl(consumerKey, consumerSecret,
YahooOAuthUrls.REQUEST_TOKEN_ENDPOINT_URL, YahooOAuthUrls.ACCESS_TOKEN_ENDPOINT_URL, YahooOAuthUrls.AUTHORIZATION_WEBSITE_URL);
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(oAuthCredentials.getConsumerKey(), oAuthCredentials.getConsumerSecret());
OAuthProvider provider = new CommonsHttpOAuthProvider(oAuthCredentials.getRequestTokenEndpointUrl().toExternalForm(),
oAuthCredentials.getAccessTokenEndpointUrl().toExternalForm(), oAuthCredentials.getAuthorizationWebsiteUrl().toExternalForm());
System.out.println("Fetching request token from Yahoo!...");
// We do not support callbacks, thus pass OOB
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
System.out.println("Request token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization");
System.out.println("Enter the verification code and hit ENTER when you're done");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();
System.out.println("Fetching access token from Yahoo!...");
provider.retrieveAccessToken(consumer, code);
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
HttpGet request = new HttpGet("http://api.delicious.com/v2/posts/update");
consumer.sign(request);
System.out.println("Sending update request to Delicious...");
HttpClient httpClient = new DefaultHttpClient();
HttpResponse response = httpClient.execute(request);
System.out.println("Response: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
For more information on OAuth see Yahoo! Developer Network and Signpost.
© 2010 - 2011 wad'n dad'n deliciousJ(at)wadndadn.de |
Bookmark this on Delicious