Hace poco posteé un artículo sobre cómo tweetar con PHP. Normalmente estos updates van acompañas de un enlace con información más completa, y para eso tenemos tinyurl.

El siguiente código se conecta a la API de tinyurl y te devuelve el valor de la URL empequeñecida, así de sencillo:

    function tinyURL($url)
    {
        $context = stream_context_create(array(
            'http' => array(
              'method'  => 'GET',
              'timeout' => 5
            ),
        ));
        $ret = file_get_contents('http://tinyurl.com/api-create.php?url='.urlencode($url), false, $context);
        return $ret;
    }

Y ésta sería la forma de utilizar en un caso “práctico”:

tweet('Ya tengo blog, '.tinyURL('http://www.loalf.com'), 'loalf', 'Pa$$');

Compártelo:
  • Print this article!
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • LinkedIn
  • Ping.fm
  • RSS
  • Twitter