How to Use the Twitter API

Here is a PHP class to push Twitter updates from your own web app:

<?
class twitter {
    function 
twitter($username,$password) {
        
$this->username=$username;
        
$this->password=$password;
        
$this->baseurl "http://twitter.com/";
    }
    
    function 
tweet($message) {
        
# status
        
$url $this->baseurl."statuses/update.xml";
        
$session curl_init();
        
curl_setopt $sessionCURLOPT_URL$url );
        
curl_setopt $sessionCURLOPT_HTTPAUTHCURLAUTH_BASIC );
        
curl_setopt $sessionCURLOPT_HEADERfalse );
        
curl_setopt $sessionCURLOPT_USERPWD$this->username ":" $this->password );
        
curl_setopt $sessionCURLOPT_RETURNTRANSFER);
        
curl_setopt $sessionCURLOPT_POST1);
        
curl_setopt $sessionCURLOPT_POSTFIELDS,"status=" $message);
        
$result curl_exec $session );
        
curl_close$session );
        print 
$result;
    }
}
?>


Comments

It's quiet in here...Add your comment