views:

56

answers:

2

I have an app where I pull in tweets with a certain hash tag. When I find the hash tag the app automatically creates a user if they don't exist. When the user logs in via Twitter, I want be able to present them with their friends which are also using the app. The problem is for Twitter users with a ton of friends there is a max response of 100 and I'd have to continue to hit the API to 10 times to get the users of someone with 1000 friends.

Also, when pulling the friends info, should I just cache the friends in an array and move to a matched array so I don't have to hit the API again?

A: 

Given that most Twitter apps have a per hour limit on API calls you really should cache pretty much everything. Check the cache to see if you have the data first before pulling down any information.

If you are worried about how up-to-date the data is then put a time stamp in the cache. When you try to access something from the cache check whether the time difference to now is larger than some defined amount (depending on how fresh your data needs to be & how much you can keep hitting the server with requests) and if it is go and refresh the data.

This is a little like writing a good web crawler (which Jeff Atwood seems to suggest has only been done by Google). It is easy to write something that will attempt to pull down everything from the internet at once but it is more difficult to write something that will do it in a sustainable, manageable way.

Twitter have been sensible in forcing people to think through these issues by placing a "per-hour access count" on their API.

Matt Breckon
There are examples of similar instances of what I want to do at http://www.tweetfriends.com/ and http://friendorfollow.com/ except I'll be comparing against my own data rather than another Twitter user.
Seth
Sorry, I'm at work now and I can't access twitter related sites - I'll have a look when I get a chance.
Matt Breckon
I've written a twitter app that finds all my followers, their followers and the connections between them. See http://www.softwareproductdev.com. I used a technique similar to the one I've described - the software can use up it's 150 accesses and can then be re-run at any point and continue with any followers that hadn't yet been downloaded.
Matt Breckon
A: 

I found an API call that just returns the IDs of a Twitter user's friends and returns upwards of 5000, however, tries to return all. The docs for the call are here: http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-friends%C2%A0ids

What I did was took the response from the API call and created a SQL statement utilizing IN. This way, I now can handle all my sorting and so forth via SQL, rather than doing a nasty array compare.

Seth