Codice: Seleziona tutto
<?php
function tweet($username, $password, $status)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://twitter.com/statuses/update.xml?status=" . urlencode(stripslashes(urldecode($status))));
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch);
$headers = curl_getinfo($ch);
curl_close($ch);
if ($headers['http_code'] == '200')
{
return true;
}
return false;
}
?>
- username = nome utente dell'account
- password = password dell'account
- status = nuovo status
Ritorno
La funzione ritorna un valore booleano, true se lo status è stato aggiornato, altrimenti false.
N.B.: Tale funzione sfrutta l'autenticazione base, e pertanto, Twitter ha deciso di non offrire più questo tipo di autenticazione dal 30 giugno 2010.