I have to add some extension to a site, to post tweets onto the site’s Twitter account, when a new post submitted. I tried some version, first the old way with curl, then some versions with oAuth, but all solution based on a manual user login. I don’t want to force the site admin, to every time log in to the twitter too, when submits a post.

Finally I found the most easy solution, what don’t need any specialties. The solution is based on the post of Jaisen Mathai http://www.jaisenmathai.com/articles/twitter-php-oauth.html

The steps;

 

1. Register the application on the Twitter as Browser application.

2. Add the following part to the PHP code of your site; (The EpiCurl,EpiOAuth,EpiTwitter are downloadable from this site; http://www.jaisenmathai.com/articles/twitter-php-oauth.html )

include ‘twitter/EpiCurl.php’;
include ‘twitter/EpiOAuth.php’;
include ‘twitter/EpiTwitter.php’;
include ‘twitter/secret.php’;   <– the secret.php contains the consumer_key & consumer_secret values.

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
$oauth_token = “—> the oauth token from the twitter <—“;
$oauth_secret = “—> the oauth token secret from the twitter <—“;
$twitterObj->setToken($oauth_token, $oauth_secret);
$message=”—> The message, what you want to post onto the twitter <—“;
$update_status = $twitterObj->post_statusesUpdate(array(‘status’ => $message));
$temp = $update_status->response;
—>code if you want to process the response<—

This small codepart will send the tweet when you call the function, without you have to login onto the twitter manually.