Google URL Shortener at goo.gl is a service that takes long URLs and squeezes them into fewer characters to make a link that is easier to share, tweet, or email to friends. Users can create these short links through the web interface at goo.gl, or they can programatically create them through the Google URL Shortener API. With the URL Shortener API you can write applications that use simple HTTP methods to create, inspect, and manage goo.gl short links from desktop, mobile, or web.
Note : As of March 30, 2019, the goo.gl URL shortener was shut down. Please see thisfor alternatives.
Here are list of Google URL Shortener API methods that can be used in our applications,
- get – Expands a short URL or gets creation time and analytics.
- insert – Creates a new short URL.
- list – Retrieves a list of URLs shortened by a user.
url.getmethod gets expansion information for a specified short URL. For the given short URL, the url.get method returns the corresponding long URL and the status.
url.insertmethod creates a new short URL. Authentication is optional for the url.insert method. If an authentication token with access to https://www.googleapis.com/auth/urlshortener is provided, the method creates a short URL for the authenticated user. The short URL created will appear in the authenticated user’s list method results and on their dashboard at http://goo.gl/. If no authentication is provided, the short URL that the method creates is not associated with any particular account.
url.listmethod retrieves a list of URLs shortened by the authenticated user. The url.list method returns a paginated list of information about short URLs created by a user, sorted in reverse chronological order. Each returned resource contains the short URL, long URL, creation timestamp, and status.
Source Code :
We are using Google APIs Node.js Client and Express.js to demonstrate the programmatic methods of using Google URL Shortener. Each methods on the APIs is demonstrated with different routing.
Note : Please replace API keys, Client ID and Client Secret with your application details.