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

<?php
/*
RSS to Twitter v0.1
by paul stamatiou
of http://paulstamatiou.com
based on code from

http://morethanseven.net/posts/posting-to-twitter-using-php

mods and adaptation from Tayeb Habib http://redacacia.wordpress.com and http://myciw.org
with futher modifications by Mikey Beck http://mikeybeck.com/
*/
include('parse.php');
require_once(
'twitteroauth/twitteroauth.php');
require_once(
'twitteroauth/secrets.php');

$connection = new TwitterOAuth ($consumer_key$consumer_secret$access_key
              
$access_secret);
$newpost=4;
while (
$newpost>=0// checks last 5 posts
{
$feed "http://mikeybeck.com/blog/rss.php"//the feed you want to micro-syndicate
$rss = new lastRSS;

$url "http://mikeybeck.com/blog/";
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("http://tinyurl.com/api-create.php?url=" . $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));
$newpost--;
}
?>

parse.php source code

secrets.php source code

twitteroauth.php source code

OAuth.php source code


 

Share this!


facebooktwittergoogle_pluslinkedin


 

Leave a Reply