Se avete utilizzato Twitter per molto tempo, probabilmente sarete consapevoli della loro imponente API. Attraverso queste API, è possibile eseguire quasi tutte le funzioni che svolgiamo sul sito officiale Twitter.com.
In questo tutorial imparerete come scrivere post su Twitter attraverso script PHP.
$twitter_api_url = "http://twitter.com/statuses/update.xml"; $twitter_data = "status=Tuo testo"; $twitter_user = "tua_username"; $twitter_password = "tua_password"; $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); if ($httpcode != 200) { echo "Si è verificato un errore durante la pubblicazione!"; } else { echo "Messaggio pubblicato con successo!"; }
Come potete vedere, abbiamo utilizzato i CURL per inviare (tramite POST) il nostro testo e le credenziali d'accesso all'URL http://twitter.com/statuses/update.xml
Potete trovare maggiori informazioni su Twitter API Wiki, la documentazione ufficiale delle API di Twitter.


2 Responses
Ciao ho provato il tuo script ma mi da sempre l’errore:
Si è verificato un errore durante la pubblicazione!
Hai qualche idea del motivo.
Grazie.
Ciao, ho provato e riprovato, ma i post non vengono pubblicati. Come mai?
Sai aiutarmi?