Acortar URLs mediante goo.gl y PHP
La API de Google para acortar URLs permite acortar URLs, recuperar info del link original y las URLs acortadas de un usuario, aunque para usarlo se necesita crear una clave y dar de alta proyecto.
El resto es fácil, acceso mediante CURL y listo:
define('GOOGLE_API_KEY', '[insert your key here]');
define('GOOGLE_ENDPOINT', 'https://www.googleapis.com/urlshortener/v1');
function shortenUrl($longUrl)
{
// initialize the cURL connection
$ch = curl_init(
sprintf('%s/url?key=%s', GOOGLE_ENDPOINT, GOOGLE_API_KEY)
);
// tell cURL to return the data rather than outputting it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// create the data to be encoded into JSON
$requestData = array(
'longUrl' => $longUrl
);
// change the request type to POST
curl_setopt($ch, CURLOPT_POST, true);
// set the form content type for JSON data
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
// set the post body to encoded JSON data
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($requestData));
// perform the request
$result = curl_exec($ch);
curl_close($ch);
// decode and return the JSON response
return json_decode($result, true);
}
$response = shortenUrl('http://phpriot.com');
echo sprintf(
'%s was shortened to %s',
$response['longUrl'],
$response['id']
);
Shortening URLs for goo.gl with Google’s URL Shortener API
Vía / PHPDeveloper.org
Serendipity es un CMS basado en PHP que nos permite llevar nuestro blog o nuestra web completa. Ofrece flexibilidad, fácil de ampliar y con un framework sencillo de usar.

Google ha comprado un algoritmo de búsqueda creado por un estudiante israelí de la Universidad New South Wales en Australia, en donde está realizando el doctorado. Según esta misma universidad, la cual tiene la patente del algoritmo, Yahoo y Microsoft también están negociando para adquirir el algoritmo.
Simple curiosidad, ¿por qué no permites poner comentarios en posts antiguos?
Porque se llenan de spam 🙁