rss2twitter.php source code

Posted on

This is the all new updated code. It’s a bit more difficult to implement your own automatic twitter feed
now, but with the help of a few kind people who have done all the hard work already, it’s not too bad. OAuth
authentication is used, so no username or password is required. It just uses four different apparently randomly
generated keys of about 20-50 characters’ length instead.

You can still view the old code here, but due to recent Twitter updates, it won’t
work without modification, because basic authentication is no longer supported by the Twitter API.

parse.php | secrets.php | twitteroauth.php | OAuth.php

RSS to Twitter v0.1
by paul stamatiou
based on code from

mods and adaptation from Tayeb Habib and
with futher modifications by Mikey Beck

$connection = new TwitterOAuth ($consumer_key$consumer_secret$access_key
while (
$newpost>=0// checks last 5 posts
$feed ""//the feed you want to micro-syndicate
$rss = new lastRSS;

$url "";
if (
$rs $rss->get($feed)){
$title $rs[items][0][title];
/* total length of tweet is 140chars. The +7 at the end is for the 
       extra characters that are always used (spaces, dots etc)         */
$tweetlen 140 - (strlen($title) + strlen($url) + 7); 
//body of tweet as long as possible
$tweetbody substr($rs[items][0][description], 0$tweetlen); 
//$url = $rs[items][0][link];
} else { die('Error: RSS file not found, dude.'); }
//$tiny_url =  file_get_contents("" . $url);
$status $title " - " $tweetbody "... " $url;
//echo $status; //just for status if you are directly viewing the script

$parameters = array('status' => $status);

print_r ($connection->post('statuses/update',$parameters));

parse.php source code

secrets.php source code

twitteroauth.php source code

OAuth.php source code


Share this!



3 Responses to “rss2twitter.php source code”

  1. june says:

    Hi mike,

    have you tried putting the g00gle news rss?

    I’m having broken news url.

    tried using magpie but got only one tweet poted!

  2. june says:

    it seems the problems are on the parse.php
    if you use magpie the only problem is that only one news will be posted.

  3. mikey says:

    Hi June

    Thanks for that – I’m not sure what you mean by ‘putting the Google News RSS’ though.
    I can try fixing parse.php if I get a free moment sometime in the near future.


Leave a Reply