Revision: 45020
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at April 22, 2011 07:16 by lasavior
Initial Code
function getgoogl($glurl, $apikey) { $userurl = rawurlencode($glurl); $ch = curl_init('https://www.googleapis.com/urlshortener/v1/url?key='.$apikey); curl_setopt_array($ch, array( CURLOPT_POST => TRUE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HTTPHEADER => array('Content-type: application/json'), CURLOPT_POSTFIELDS => json_encode(array('longUrl' => $userurl)) )); $chresults = json_decode(curl_exec($ch)); curl_close($ch); return $chresults->id; }
Initial URL
http://snipt.org/xglpp
Initial Description
I needed a simple function to shorten a link with goo.gl and wrote this, thought it may help someone. Note: you still need an API key from goo.gl
Initial Title
Shorten with goo.gl
Initial Tags
url, google
Initial Language
PHP