Twitter Icon

Auto Post to Twitter

Well after I solved my task of auto posting to Facebook, I got assigned with doing the same thing but for Twitter. Luckily, this is so much easier than posting to Facebook.

Register Your Twitter Application

Start by creating an application with Twitter. You can fill out the info however you like. None of it will matter for automatically posting tweets.

Download the Twitter OAuth API Library

Twitter has a bunch of different API libraries but I used TwitterOAuth by Abraham Williams. Download it here.

Create the Auto Tweeter

Now lets create the auto poster/tweeter. It’s really easy. I couldn’t believe how painless this was.

// Twitter Class

// Twitter Connection Info
$twitter_access_token = 'xxx';
$twitter_access_token_secret = 'xxx';
$twitter_consumer_key = 'xxx';
$twitter_consumer_secret = 'xxx';
// Connect to Twitter
$connection = new TwitterOAuth($twitter_consumer_key, $twitter_consumer_secret, $twitter_access_token, $twitter_access_token_secret);
// Post Update
$content = $connection->post('statuses/update', array('status' => 'Test Tweet'));

The consumer key and secret are under your Twitter application details and the access token and secret are under Application details -> My Access Token. Plug those in above and you’re good to go.

Continue Reading

  • No Related Posts
  • hi,i want to know,how can i post a link status to twotter.

    • Skye

      Can you expand on that? How is that different from the post above?

  • I forget the characters and links to open spaces, and Oh!
    But today I encountered a problem,
    The script in the php command mode does not seem to effect, the message is not sent out
    Very strange, I execute in the browser no problem.

  • todd

    I just have to say thanks. This worked perfectly. I was thinking it would be a pain then came upon your site. (I was looking for email piping info but also had a twitter dilemma). Both are satisfied. Great stuff.