How to Use the Twitter API

By 28 Nov 2008 | Comment
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

Recent Updates:

19 May : Heating Oil Thefts - Stay Alert!
19 May : Pro Blaze Overshoes pass the test
15 May : Get a CentOS Server Web-Ready
13 May : Keeping your iPhone secure
06 May : Nero, Claudius and a rather dead mouse
19 May : Domestic Heating Oil Prices: Know the Market!
19 May : Sports Gear: Under Test
15 May : Rackspace Cloud Hosting
13 May : iPhone 4
06 May : Cats
19 Mar : Time Trial Results
25 Nov : Piano for the Amateur
14 Nov : Measure
02 Nov : Book Reviews
12 Oct : Simple Programming Exercises

Popular Searches: