https://api.twitter.com/1/statuses/user_timeline.rss?screen_name=username
To get RSS reading back again I decided to create my own feed and you can do the same. I made heavy use of Adam Green’s code from 140dev.com and he in turn uses Matt Harris’ OAuth library from https://github.com/themattharris/tmhOAuth.
You will need web hosting that supports PHP and you can down load the files I used here (twitter-v1.1.zip updated 2-Mar-2013) and extract them to your computer.
You will also need to get some access keys from Twitter so go to https://dev.twitter.com/apps (you will need to log in with your Twitter name and password).
Click on the create a new application button then provide a name, description and a URL for the application (the URL is just where people can find out about your code – in my case it’s the blog page you’re reading).
The Callback URL is not required in this case. But if you want you can give the URL where your feed is going to be for example http://www.mywebsite.com/twitter/rss.php
Accept the terms and complete the captcha and you will be taken to the settings pages for your application.
Go to the settings tab and select Read only as the application type and update the settings.
Go back to the details tab and click the “create my access token” button at the bottom.
You will now have a page with a number of codes, you will need to copy the values for
- Consumer key
- Consumer secret
- Access token
- Access token secret
Now go to the files you downloaded, find the keys folder and in that folder is a file called personal_keys.php. Open it and edit it replacing the dummy values with the ones you copied above.
Also replace the entries in the personal_keys.php file for the domain where you will be hosting the feed. (Thanks to Terry for pointing out my earlier errors.)
Now simply upload the entire folder to your web site and test the feed by entering the appropriate URL into a browser e.g.
http://www.mysite.com/twitter.rss.php
Note, the feed is not secure and anyone with the URL can read the feed. It would be possible to have a password protected feed if you wanted to do some extra work but as tweets are public anyway I decided it wasn’t necessary for my purposes.
If you wanted something other than the home timeline you can change the URL you use to request data in the rss.php file.
$code = $tmhOAuth->request( 'GET', $tmhOAuth->url('1/statuses/home_timeline'), array( 'include_entities' => true, 'count' => 50, ) );
See https://dev.twitter.com/docs/api/1.1 for other options.
Firstly, many thanks for posting this.
I did however have a problem setting it up. I solved it by changing the Oauth object as follows:
// create the OAuth object
$tmhOAuth = new tmhOAuth(array(
'consumer_key' => $my_consumer_key,
'consumer_secret' => $my_consumer_secret,
'user_token' => $my_access_token,
'user_secret' => $my_access_token_secret,
'curl_ssl_verifypeer' => false
));
The user_token and user_secret weren’t being set correctly.
I also noticed that “Fogcat” was hardcoded so that it appeared in the rss feed, regardless of the actual user. While this didn’t seem to cause a problem I removed it by replacing both occurences with:
Thanks again and I hope the above will help others who may hit the same problem.
Glad you found it useful. I’ll edit out the hard coded bit and re-upload. (New versions of the files uploaded.)
What program do I open the downloaded program with? For me, it opens with DreamWeaver…and even then will not open
I’s a zip file so you need something to uncompress it first (like 7-zip http://www.7-zip.org/).
Then you can view the code in any text editor – it won’t do anything until you put it on a web server that supports PHP)
Thanks for posting this Geoff. Very useful information. I have a number of users who have emailed about the loss of the RSS feeds from the URL’s that my application generates for them as March rolls around. I will point them over to your post. I seem to recall that Twitter had a restriction against re-syndication of the new API that I came across somewhere in their documentation or blog posts. Do you happen to know if this approach falls within their current terms?
To be honest I have no idea about how it interacts with their current terms. I only did it so I could continue to read my Twitter stream in my RSS reader of which I’m likely to be the only subscriber. So I regarded as for personal use only.
I don’t really see how it’s any different from embedding tweets in a web page, but I might have to have a read of the terms.
I found this at https://dev.twitter.com/terms/api-terms
So as I’m not providing an API (you can’t call RSS an API) I think it’s fine.
Thanks!
This code work great, i get my timeline, but i get it like HTML code :/ Can you help me?
Well an RSS feed is just an XML file and it’s designed for use by a feed reader rather than a human. Normally a browser will make a successful attempt and converting an XML RSS feed into something readable. What are you using to look at the feed?
Doesn’t the code in the zip file use the API version that they are going to shut down? Shouldn’t it use version 1.1? Or what am I missing?
Yes looks like you’re right
http://140dev.com/twitter-api-programming-blog/twitter-api-ebook-single-user-twitter-oauth-programming/
I’ll try and get it converted this weekend and update the files.
I’ve updated the files to make sure they use the v1.1 API and I’ve included the latest copy of the OAuth library that was available at the time of the update.
If you’ve already used the files you should upload all the files in the new zip except personal_keys.php. Replacing any existing ones.
You also no longer need to include your twitter name in the personal keys file.
Is it possible to retrieve another user’s public tweets using this script? I’ve tried replacing home_timeline with user_timeline?user_id=12345&count=5 but only my own timeline shows up.
Thanks.
Ah! Figured it out just after I posted that last comment. It should be like:
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/statuses/user_timeline.json'),
array(
'include_entities' => true,
'count' => 5,
'user_id' =>12345,
)
);
To get the tweets of another user ID.
Glad you figured it out.
RSS still works for now, but I’m not sure how much longer this will last.
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name={TWITTER-USERNAME}
Replace “{TWITTER-USERNAME}” with a valid Twitter username.
Wonderful, thanks for this Geoff. It’s working smoothly on my forum.
Hi, great article. I have been trying to get this to work for search hashtags without success. Could someone be so kind as to let me know what the code should change to for a search hashtag feed? Thanks.
Can you do it with a search?
https://dev.twitter.com/docs/api/1.1/get/search/tweets
This might also be useful
http://stackoverflow.com/questions/2714471/twitter-api-display-all-tweets-with-a-certain-hashtag
I’ve worked out the search thing with DoubleSix’s help there is a version where you can search for hash tags, or indeed any string such as “apples OR oranges” here.
Hello,
The new RSS feed for a user timeline is indeed :
http://api.twitter.com/1/statuses/user_timeline.rss?screen_name={TWITTER-USERNAME}
But does someone knows what are the new RSS feeds for LISTS and SEARCHES ?
(before it was :
– http://api.twitter.com/1/{TWITTER-USERNAME}/lists/{TWITTER-USERLIST}/statuses.atom : for LISTS
– http://search.twitter.com/search.atom?lang=en&q=%20HEYWORD%20: for SEARCHES)
Thanks a lot !
Regis
Hello me again,
The code is still working fine and my RSS feed poster is posting the results to a sub-forum of mine. What I wanted to ask is there a limit or some sort of block stopping my RSS feed poster from posting tweets every 60 minutes?
I have setup the poster so that it should post a new tweet every 60 minutes but it seems to only pick one out every.. week?
Many thanks
I’m not sure I understand what you mean by “RSS feed poster”. Is this a variant of the code that makes a new tweet for you?
Hi
I’ve set this up on Google App Engine using http://www.webdigi.co.uk/blog/tag/quercus/. I’m getting the following error.
tmhOAuth.php:442: Fatal Error: ‘hash_hmac’ is an unknown function.
I’m not good at php. I guess hash_hmac function isn’t supported.
Is there any work around.
Thanks in Advance.
hash_hmac seems to be used by the tmhOAuth package and should be part of PHP versions 5.1.2 and above).
http://php.net/manual/en/function.hash-hmac.php
I don’t know anything about the Google App Engine but it looks like their version of PHP doesn’t support it for some reason. What version of PHP does the GAE provide?
If it’s lower this page says it provides a version of hash_hmac for PHP 4
http://www.ulrichmierendorff.com/software/aws_hmac_signer.html
Ahh just checked your link and it seems Quercus is a Java implementation of PHP so it probably doesn’t support all PHP functions. You could try implementing your own version of the function – maybe the code I linked to will help.
Hi Admin
Thank you very much for your response.
Yes you’re right. Quercus, a Java implementation of PHP is not supporting the function hash_hmac.
I’m not good at PHP, so couldn’t fix it despite of your suggestions.
Ok No problem, the code is working fine when hosted on a different php hosting service.
And many thanks to you for this very useful post.
Cheers
Bob
You could try adding the php files in this zip file to the same directory as the rss.php file and add the line
include("php4_hmac.php");
after the requires at the top of rss.php.
I’ve not tested it – so no promises.
Has anyone used the above code to get “list” statuses? I can get the home timeline to work ok, but can’t get lists to work. I keep getting this error: “You must specify either a list ID or a slug and owner,” even though I provide the requested info. Here’s a snippet of what I modified in the RSS file:
$code = $tmhOAuth->request(
'GET',
//$tmhOAuth->url('1.1/statuses/home_timeline'),
$tmhOAuth->url('1.1/lists/statuses.json?slug=mylistslugname&owner_screen_name=myscreenname'),
….I’ve obviously replaced “mylistslugname” and “myscreenname” with the appropriate values, but it still doesn’t work. Also, I’ve tried passing the “list_id” name/value, but that still gives me the same error message. Wondering if it’s my code, or if lists are just borked right now. Thanks.
Have you tried
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/lists/statuses'),
array(
'slug' => 'mylistslugname',
'owner_screen_name'='myscreenname',
)
);
That worked! Thanks so much Geoff…your tutorial and extra help are much appreciated (esp. since there isn’t any documentation on a lot of this stuff). Well, nothing that an avg Joe like myself can decipher anyways. Cheers!
It seems that twitter have disconnected the RSS today. I have uploaded the code and configured as suggested and it all works fine. Thank you very much Geoff.
Any idea how to configure it just to get my own posts and not everyone that I follow?
If you use GET statuses/user_timeline instead of home_timeline I think that should do it.
https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline
Thank you Geoff. Really appreciate your help. Works fine.
Hey all,
I’m new to this all and I’m not technically inclined. but I was wondering if there could be a way to do this through yahoo pipes? I have no idea if this makes sense.. but something like this:
http://www.monofactor.com/1386/displaying-twitter-feed-via-yahoo-pipes/
If someone more knowledgeable than me could look in to it it would be great.
Thanks,
Aidin
Sorry, I’d not even heard of Yahoo pipes before your comment so I’m not going to be much help.
Hi. Thanks for share all this! If you don’t mind, I will link this post from my blog in a new article trying to explain how to create your own Twitter’s feed NOW (in spanish). But, its your code, so I want people know that it is your work and I’m only the messenger. Mine it is not a plain translation, but still depends on your development. Is this OK?
BTW, I used it to get my favorites… In that case, “$tmhOAuth->url(‘1/statuses/home_timeline’),” must be “$tmhOAuth->url(‘1.1/favorites/list’),”
🙂
That’s fine, feel free to go ahead.
Hello,
I am very green to coding. Dumb question, but, is this available in a quartz composer overlay (via RSS feed). Or is that impossible to get a twitter RSS feed through QC with API v1.1????
Sorry, I’d never heard of Quartz Composer until I just Googled it. It’s some sort of music program for Macs? So no I don’t think it would work with that.
Awesome post.
I was having trouble getting Twitter Search results.
Can anyone point me the right way ?
Thanx in advance.
You’d need to change the tmhOAuth request to something like:
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/search/tweets'),
array(
'q' => 'search string',
'include_entities' => true,
'count' => 50,
)
);
That’s totally untested but the documentation is here:
https://dev.twitter.com/docs/api/1.1/get/search/tweets
Heh, thanx I kinda had that, but doesn’t work. OMG I’m so tired I know I’m missing something stupid.
array(
'q' => 'DoubleSixx',
'include_entities' => true,
'count' => 50,
)
In what way doesn’t it work? A program error or no results?
So sorry I didn’t include what was happening, running on very little sleep.
The page generates four links. The first is a square with the following link : https://twitter.com/DoubleSixx/statuses/
Next is an @ with a link to https://twitter.com, followed by another square with a link to my statuses and finally an @ with twitter’s url.
PHP is not my primary language so I’m struggling.
Hope you can help. Thanx in advance.
Hmmmm, it seems you might be getting further than me I keep getting a 405 error when I submit the search query. Can’t work out at the moment why that should be.
I get the same output as DoubleSixx. And I’m not a programmer either 🙁
See my reply to Andy higher up, I figured it out with DoubleSix’s help and there is a search version of the code.
Geoff, would you mind contacting me at my email address in this post? I am developing an open source version of the old Twitter user timeline, favorites, mentions, and search feeds that I would like to place on GitHub. I’d like to include some of your code and wanted to see if you are interested in collaborating on the project and what type of licensing you have applied to the home timeline code that you developed here.
Thanks much,
Chris
Geoff,
Emailed you, guess I hit the limit of replies here.
I’ve enabled some deeper nesting of replies now.
Pingback: Crear RSS de Twitter para Api 1.1 | Salinasjavi's Blog
Hello! Thanks for your app. I tweaked it a bit so that if you add the parameter ?name=sometwitterusername
it will show that user’s stream instead of yours.
Maybe you want to integrate it in the original since it doesn’t change the original behavior and just adds new features.
Instead of
$userInfoObj = json_decode($tmhOAuth->response['response']);
//tmhUtilities::pr($userInfoObj);
// extract certain info about the user
$twitterName = $userInfoObj->screen_name;
$fullName = $userInfoObj->name;
$twitterAvatarUrl = $userInfoObj->profile_image_url;
$feedTitle = $twitterName . ' Twitter ' . $twitterName . 'Timeline';
// request the home time line - the last 50 item
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/statuses/home_timeline'),
array(
'include_entities' => true,
'count' => 50,
)
);
The code now contains
if ($_GET["name"]) {
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('/1.1/users/show.json'),
array(
'screen_name' => $_GET["name"],
)
);
if ($code 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("users_show connection failure");
}
$userInfoObj = json_decode($tmhOAuth->response['response']);
//tmhUtilities::pr($userInfoObj);
// extract certain info about the user
$twitterName = $userInfoObj->screen_name;
$fullName = $userInfoObj->name;
$twitterAvatarUrl = $userInfoObj->profile_image_url;
$feedTitle = $twitterName . ' Twitter ' . $twitterName . 'Timeline';
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('/1.1/statuses/user_timeline.json'),
array(
'screen_name' => $_GET["name"],
'include_entities' => false,
'skip_status' => true,
)
);
} else {
$userInfoObj = json_decode($tmhOAuth->response['response']);
//tmhUtilities::pr($userInfoObj);
// extract certain info about the user
$twitterName = $userInfoObj->screen_name;
$fullName = $userInfoObj->name;
$twitterAvatarUrl = $userInfoObj->profile_image_url;
$feedTitle = $twitterName . ' Twitter ' . $twitterName . 'Timeline';
// request the home time line - the last 50 item
$code = $tmhOAuth->request(
'GET',
$tmhOAuth->url('1.1/statuses/home_timeline'),
array(
'include_entities' => true,
'count' => 50,
)
);
}
Thanks for the addition
Hello, I tried the code given by Nicola,
and I do not get it to work. I get a:
Response: Internal Server Error (500)
I just deleted the ‘old’ piece of code and copy pasted the new code.
really don’t know where to look or what to do since I am not a programmer, sorry for that.
I got the rss.php and searchrss.php working.
So I hope you could help,
thanks
There is an error in the code (probably caused by wordpress when it was copied and pasted.
Where it says
if ($code 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("users_show connection failure");
}
it should say
if ($code <> 200) {
tmhUtilities::pr($tmhOAuth->response['response']);
die("users_show connection failure");
}
Yes Thanks it is working now.
If the twitter API is providing geolocation then,
Is there a way to get geolocations from a tweet? is there a geoloction tag?
And when using searchrss.php is it possible to use geolocation (gps coordinates) instead of a place name to get tweets from a area?
Thanks in advance
For searching – yes there is a geocode parameter described in the documentation:
https://dev.twitter.com/docs/api/1.1/get/search/tweets
And there are coordinate and place values in the returned tweet objects:
https://dev.twitter.com/docs/platform-objects/tweets
As others have said, thank you for putting in the work to make this happen! I just wanted to say that I did have some problem with the short tags in the rss.php file. I would imagine that some users might not have a host that would support short tags so it might be desirable to change that aspect of the code if you happen to do a revision at some point. Just a thought!
Yes, good point, I’ve gotten a bit lazy with the short tags, I’ll correct that next time I do an update.
Hi, I followed your instructions exactly in uploading the files, and getting authentication keys. I then updated the personal_keys.php file but I’m getting the following error – “verify_credentials connection failure”
I’m certain that the key, secret, token and token_secret are entered correctly but I’m unsure about the $my_domain value – I’ve tried the URL of the feed as well as the URL of my website.
Any help?
Make sure there are no spurious spaces in the strings you’ve assigned the keys and that you’ve uploaded your edited keys file to the right place.
For the domain I just use the full URL of my site (with the http:// in front). Sorry, been busy the last few days, I’ll have a look after the weekend.
Here are some easy workarounds for the API change. You access all feeds timelin, hash tag, mention, etc.
http://ta.gd/how-to-get-twitter-rssfeed-2013
Hi
Thanks for this, but I’m getting the following error:
This page contains the following errors:
error on line 3 at column 25: Unescaped ‘<' not allowed in attributes values
Any ideas?
Which file does it say the error is in?
Pingback: Show posts from Google+, Facebook and Twitter in your WordPress blog | WebdesignZ
Pingback: Moving at the Speed of Creativity | Playing with FeedWordPress: Planning for the Classroom Newspaper of Now
Pingback: Playing with FeedWordPress: Planning for the Classroom Newspaper of Now – American Fido
Pingback: Playing with FeedWordPress: Planning for the Classroom Newspaper of Now – Web Guy Help