Using goo.gl API to shortlink many longlinks

2k Views Asked by At

I'm looking for a simple example where I can feed through a long link using the Google API and then shorten it with the API and output the results. I already have a DB setup with the long links, and want to loop through the DB and do this multiple times until all long links in the DB are shortlinked and then printed out.

Does anyone have a working solution for this or an example to get me started? Would be greatly appreciated.

Thanks in advance for your help!

1

There are 1 best solutions below

0
On

From the Google APIs Client Library for PHP, there is an example for urlshortener. It boils down to:

$url = new Google_Url();
$url->longUrl = $_GET['url'];
$short = $service->url->insert($url);