Reputation: 15895
I am using twitter latest REST API v1.1 and application-only authentication to fetch 8 users today's feed/status to show in a listView. I was using https://api.twitter.com/1.1/statuses/user_timeline.json?count=10&exclude_replies=true&screen_name=UserName
to fetch each user feed. But I don't know how to fetch only today's feed. So I fetched around latest 10 feed by using &count=10
and filter these based on today's date. But it seems to be a poor way. Also I want to fetch my 8 user's feed together for better performance because fetching 8 user's feed individually is time expensive and not a good way. So
How can I get a JSON feed of today's tweets of 8 users in one request? What should be the URL?
Upvotes: 1
Views: 1925
Reputation: 2521
The statuses/user_timeline
API endpoint only supports getting the tweets for a single user, so if you want to get the tweets for eight users you'll need to make 8 requests.
There is a way around this though...
If you make a Twitter list containing those 8 users, you can make a single request to the lists/statuses
endpoint that will return tweets from all members of the list.
Upvotes: 2
Reputation: 913
You can use Search: https://api.twitter.com/1.1/search/tweets.json?q=from%3A[twitter_username_1]+OR+from%3A[twitter_username_2]
Just make sure you don't go over a certain number of users (15-20), otherwise it returns Bad Request.
For PHP users:
$twitter_users = array('katyperry','BarackObama','ladygaga','YouTube');
$search_query = implode("+OR+from%3A", $twitter_users);
$feed_url = "https://api.twitter.com/1.1/search/tweets.json?q=from%3A".$search_query;
Upvotes: 0