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.)
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
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!