TweetRecent I have developed an auto tweet application using twitter OAuth and PHP and running this application in a particular interval of time using Cpanel Cron job.Here I will explain you how to make your auto tweet application.
First register your new application in twitter. Click here to register a new twitter application and follow the steps. After successful registration you will get permission to access your twitter account using OAuth. Same time your OAuth key and consumer key etc.. will be provided by twitter.
Now you are ready to develop the application. Download the example file and extract it. Open the index.php with your editor. It will be look like below
$consumerKey = 'Consumer-Key'; $consumerSecret = 'Consumer-Secret'; $oAuthToken = 'OAuthToken'; $oAuthSecret = 'OAuth Secret'; //Find above details in Twitter Application require_once('twitteroauth.php'); $tweet = new TwitterOAuth($consumerKey, $consumerSecret, $oAuthToken, $oAuthSecret); require_once("config.php"); $sql=mysql_query("select url,title from article order by rand()"); $showfetch=mysql_fetch_array($sql); $tweet->post('statuses/update', array('status' => ''.$showfetch['title'].' http://www.yoursite.com/'.$showfetch['url'].''));
Here you have to change the Consumer Key, Consumer Secret, OAuth Token and OAuth Secret. You can find these values in twitter application.
Connect to database and get the title and URL from database and pass it to the tweet function. Run the script by uploading to server and check the functionality.
Now we are going to create a new cron job to run this application in every minute (In my case). Login to Cpanel and click the cron jobs. Create a new cron job and write the below command,
wget -O /dev/null -q http://www.yoursite.com/path-to-file/filename.php
Here wget: Get an HTTP resource to run the PHP,-O /dev/null: Don’t write any logs while running cron job,-q: Turn off all visual output (quiet).And hit the page to run PHP script with mentioned URL!
DONE!! Your auto tweet application is running now..Check the twitter account for PHP posting the tweet from your database.