I have the following Twitter widget JavaScript, searching for posts by @sfmta_muni that contain either “attn” or “update”. I only want to return the 5 most recent results.
As a search result I get a widget containing the last 50 matching tweets including the 5 latest tweets. As of this post, they range from 40 minutes ago to 7 days ago, from newest to olders. If I insert rpp: 5, into the code, I get 5 tweets, as desired, but unfortunately not the 5 latest matching tweets; rather they are ranging from 3 to 4 days ago, about halfway through the list of 50.
Note that there are intervening tweets for @sfmta_muni that contain neither “update” nor “attn”. These are correctly not showing regardless of presence or absence of rpp: 5, in the code.
How do I get the 5 latest matching tweets only?
Ideally, I’d like to return the 5 latest tweets that are no more than 2 hours old, but I’ll take the 5 latest tweets if that’s all I can get.
Code follows:
new TWTR.Widget({
version: 2,
type: 'search',
search: 'update OR attn from:sfmta_muni',
rpp: 5, /* this line is the one referred to above that I add or remove */
interval: 30000,
title: 'Service alerts',
subject: 'from @sfmta_muni',
width: 338,
height: 300,
theme: {
shell: {
background: '#7ec1da',
color: '#ffffff'
},
tweets: {
background: '#ffffff',
color: '#000000',
links: '#1985b5'
}
},
features: {
scrollbar: true,
loop: false,
live: false,
behavior: 'all'
}
}).render().start();
Test cases at
http://www.sfmta.com/cms/asystem/alerts_test_example1.php
http://www.sfmta.com/cms/asystem/alerts_test_example2.php
Thank you,
Charles Belov
SFMTA Webmaster
http://www.sfmta.com/webmaster