I have written a complete class which sends tweet and performs other stuff on twitter from following user to deleting Direct messages etc. But its just that I am not able to post the whole class here and explain it. I am gonna release a beta version of the class pretty soon with complete documentation, demoing and examples. Till then stay tuned and have a look at this simple script to connect to twitter API and send updates.
Just download the twitter class file and include it in your PHP script. Please note that you have to save the file as php file to include it in your php script file. I have kept the name twitter.inc.php for this example. You can give any name to the file but the class name should remain the same as twitter, as long as you do not change the contents of the file. This is going to be very basic class just to show you how to talk to twitter 🙂
The syntax to send the tweet using the above class file is as follows.
<?php //Download class from http://www.digimantra.com/resources/twitter.txt require_once("twitter.inc.php"); $credit=array(0=>"username",1=>"password"); //replace it with your username and password $t=new twitter($credit); //$t->set_debug(); // uncomment if you need to debug your script, incase of any Error, when your tweet is not being updated. $t->tweet("My First message from http://www.digimantra.com"); //pass tweet as an argument to tweet function $t->output(true); //pass true if you want browser to show the output , leave it blank if you want it to return the output instead. ?>
Validation for the 140 character limit.
Sanitizing user input including username and password.
Probably implementing OAUTH
Will release the complete class pretty soon. Till then, stay beautiful 🙂