This post is about a quick and easy integration of Google’s URL Shortener Service/API in your Java Applications using popular APIs like Scribe-Java and Google’s GSon.
The good part about this integration is that you don’t need to do additional steps to register your application with the Service APIs, because in this case, the Google’s URL Shortener Service can be accessed “anonymously”, with out having the need to register the application and performing the authentication and authorization steps.
First Download:
- Scribe-Java – A Java OAuth Library
- Google GSon – A JSON serialization/deserialization library in Java
Create a new project in IDE of your choice and add above downloaded JAR files to your project’s build/class path.
GoogleUrlShortenerApiIntegrationUsingScribeExample.java:
Compile and Run the project. You will notice an output similar to the one below in your IDE’s console:
Copy the Shortened URL, open a browser of your choice and paste the Shortened URL into the browser’s Address Bar and press ENTER. You will notice how Google’s URL Shortener Service resolves your Shortened URL to your original (longer) URL.
Shortened URL:
Original Longer URL resolved by Goo.gl:
No comments:
Post a Comment