Main menu
WalkswithMeAPI PHPGoogle URL Shortener API using PHP

Google URL Shortener API using PHP

Google URL Shortener Api is really cute and simple to use also it provide a 1,000,000 requests/day its sufficient for medium size applications. The short url’s is really important in social media platform specially twitter.

There are several blog post and official Google Client Libraries available for  Google URL Shortener Api using PHP, but most of then have a complete Google library so some one needs only this shortener API difficult to separate those file only .In this article I will explain the simplest way to use the Google URL Shortener Api using PHP.

First you have to signup with Google Developer Console

  • Create your project.
  • Click the project and open up the API’s menu under API’s and Oauth menu.
  • Search for Google URL Shortener and turn ON.
  • Generate API Key for browser application.
  • Leave the Referers as empty.
Google App Console

Google App Console

How to use Google URL Shortener API ? its really simple


require_once('GoogleApi.php');
$GoogleApi = new GoogleUrlApi(API_KEY);
$pageUrl   = 'https://www.walkswithme.net/google-url-shortener-api-using-php';
$short_url = $GoogleApi->shorten($pageUrl);
echo 'Short URL'.$short_url;

Yes, Done. If you need to expand the short URL to original URL simply use below codes.


require_once('GoogleApi.php');
$GoogleApi = new GoogleUrlApi(API_KEY);
$pageUrl   = 'https://www.walkswithme.net/google-url-shortener-api-using-php';
$expand_url = $GoogleApi->expand($pageUrl);
echo 'Original URL'.$expand_url;

Its really simple right ? you can download the Google URL Shortener Api PHP library here.

Download1830 downloads

Thanks for reading 🙂  🙂  🙂

Two thoughts on “Google URL Shortener API using PHP

Leave a Reply

Your email address will not be published. Required fields are marked *

 

FacebookTwitterGoogle+RSS