Basic Requirements
- An Twitter account.
- An Twitter app. If don't have please create @ https://apps.twitter.com
- Twitter Auth REST API, If don't have please download from https://github.com/abraham/twitteroauth
- An Server, You can also test in local wampserver or xampserver
How to Send Tweets automatically with PHP, Follow following Steps:
- Include twitter files.
require_once($_SERVER['DOCUMENT_ROOT'].'/twitteroauth/twitteroauth.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/twitteroauth/config.php');
- Collect all constants values from your twitter app (i.e apps.twitter.com)
- Add constants in TwitterOAuth constructor.
define('CONSUMER_KEY', 'YOUR_KEY'); define('CONSUMER_SECRET', 'YOUR_SECRET_KEY'); define('ACCESS_TOKEN', 'YOUR_TOKEN'); define('ACCESS_TOKEN_SECRET', 'YOUR_TOKEN_SECRET');
$twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
- Now post the message.
$message='This is test tweet.'; $twitter->post('statuses/update', array('status' => $message));
- Refresh the twitter.com, you will see your message at top of page.