Reputation: 7166
when using Twitter rails gem to fetch feed from certain users, is it possible to to this with multiple users in one query?
My main goal is to fetch the latest tweet from 5 different users. At the moment it looks like this.
@user1 = Twitter.user_timeline("user1", :count => 1)
@user2 = Twitter.user_timeline("user2", :count => 1)
@user3 = Twitter.user_timeline("user3", :count => 1)
@user4 = Twitter.user_timeline("user4", :count => 1)
@user5 = Twitter.user_timeline("user5", :count => 1)
And it feels a little bit hacky... I also could do this. But it will still be 5 queries.
@twitter_feed = Twitter.user_timeline("serenawilliams", :count => 1)
@twitter_feed << Twitter.user_timeline("FedererOfficial", :count => 1)
@twitter_feed << Twitter.user_timeline("RSoderling", :count => 1)
@twitter_feed << Twitter.user_timeline("MariaSharapova", :count => 1)
Upvotes: 0
Views: 927
Reputation: 726
Looking at the readme, it would appear there's no way to get more than one user's feed in a single query. This makes sense, because the Twitter API that it connects to doesn't support it either, so you're going to have to do each query individually.
You could simplify your queries like so, however, which might be what you're looking to do:
users = ["serenawilliams", "FedererOfficial", "RSoderling", "MariaSharapova"]
@twitter_feed = users.map {|u| Twitter.user_timeline(u, count: 1)}
This will give you an array of each user in 'users' most recent tweets.
Upvotes: 1