PHP Classes

Google URL Shortener PHP Class - Goo.gl short URL package blog

Recommend this page to a friend!
  All package blogs All package blogs   Goo.gl short URL Goo.gl short URL   Blog Goo.gl short URL package blog   RSS 1.0 feed RSS 2.0 feed   Blog Google URL Shortener ...  
  Post a comment Post a comment   See comments See comments (13)   Trackbacks (0)  

Author:

Viewers: 282

Last month viewers: 82

Package: Goo.gl short URL

This article describes how to use the Google URL Shortener PHP class to create a short URL with the goo.gl service.

It also explains how to achieve the opposite, i.e. take a goo.gl short URL, retrieve the respective long URL, as well obtaining analytics information about the clicks on the short URL links.




Loaded Article

Introduction

In this post I will describe how to use the Google URL Shortener PHP Class.

First, the purpose of the class is to shorten or expand an URL using the goo.gl Google service.

It sends a HTTP request to Google goo.gl URL shortener Web services API to generate a short URL for another given URL.

The class also send a request to expand a given shortened URL with the same Google goo.gl service.

Since version 0.2 it also can get analytics information about the accesses to the short url when retrieve the expanded URL.

Initialization

Now lets dig into how to use the class. First you need to create an object of the class like this:


    $goo = new Googl();

If you have an API key for the goo.gl service, you should specify it as a constructor parameter. You need to request an API key in Google site.


    $goo = new Googl( "API Key" ); 

Get a short URL

To get a short URL you need to call the get_short function and pass the URL as a string parameter like this:


    $r = $goo->get_short( "http://eslam.me" ); 
    print_r($r);

Expand a short URL

To expand a previously shortened URL call the get_long function passing the short url as first parameter.

Pass true as the second parameter value if you want get the access analytics information for that URL. This will make the class return statistics about the number of times the URL was followed, the browsers and countries of the users that clicked on links with the short URL, as well the referrer pages where the short URL links were clicked.


     $r = $goo->get_long( "http://goo.gl/pTgKg", true);      print_r($r);

Conclusion

Mainly that is how to use it. I tried to keep it simple and easy to use as possible. Your feedback is appreciated.

Please help spreading this class URL by sharing this short URL that points to the class page: goo.le .



You need to be a registered user or login to post a comment

1,616,107 PHP developers registered to the PHP Classes site.
Be One of Us!

Login Immediately with your account on:



Comments:

3. SEO - ashutosh (2013-10-22 03:14)
make seo simple... - 2 replies
Read the whole comment and replies

5. ralph lauren polo sale uk - marklin2010 (2013-10-22 03:06)
mbt... - 1 reply
Read the whole comment and replies

4. Exactly what i was looking for ! - Alano Teles (2011-11-19 17:16)
Thanks, Eslam !... - 1 reply
Read the whole comment and replies

1. Goo.gl short URL - Fabio Adorno (2011-10-14 12:59)
Goo.gl short URL... - 4 replies
Read the whole comment and replies

2. fashinefa - fashinefa (2011-10-14 09:29)
Womens Ture Religion Crops jeans... - 0 replies
Read the whole comment and replies



  Post a comment Post a comment   See comments See comments (13)   Trackbacks (0)  
  All package blogs All package blogs   Goo.gl short URL Goo.gl short URL   Blog Goo.gl short URL package blog   RSS 1.0 feed RSS 2.0 feed   Blog Google URL Shortener ...