Script en php per enviar missatges a un compte a twitter

Escrit per admin | Linux | Monday 23 November 2009 4:22 pm

Aquest script en php serveix per enviar a un compte a twitter missatges.
La variable $ missatge la podriem treure de per exemple l'últim titular d'un article al nostre blog o el que vulguem enviar.
140 caràcters de merda és el límit.

$mensaje = "Hola mundo";
// los datos de la cuenta en twitter
$twitter_api_url = "http://twitter.com/statuses/update.xml";
$twitter_data = "status=$mensaje";
$twitter_user = "cuenta@twitter.com";
$twitter_password = "passwordtwitter";
// el tinglado
$ch = curl_init($twitter_api_url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $twitter_data);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "{$twitter_user}:{$twitter_password}");
$twitter_data = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
// si falla o no el envio y queremos por algun motivo mostrarlo
if ($httpcode != 200) {
echo "Algo ha fallado.";
}else{
echo "
“;
echo “ Mensaje enviado “;
echo “
“;
}
?>

A arcardes usem alguna cosa així.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment