views:

178

answers:

3

Hello All,

I'd like to set up a coldfusion page that will pull the status updates from my own facebook account and twitter accounts and put them in a SQL database along with their timestamps. Whenever I run this page it should only grab information after the most recent time stamp it already has within the database.

I'm hoping this won't be too bad because all I'm interested in is just status updates and their time stamps. Eventually I'd like to pull other things like images and such, but for a first test just status updates is fine. Does anyone have sample code and/or pointers that could assist me in this endeavor?

I'd like it if any information relates to the current version of the apis (twitter with oAuth and facebook open graph) if they are necessary. Some solutions I've seen involve the creation of a twitter application and facebook application to interact with the APIs; is that necessary if all I want to do is access a subset of my own account information? Thanks in advance!

+1  A: 

I would read the max(insertDate) from the database and if the API allows you, only request updates since that date. Then insert those updates. The next time you run you'll just need to get the max() of the last bunch of updates before calling for the next bunch.

You could run it every 5 minutes using a ColdFusion scheduled task.

How you communicate with the API is usually using <cfhttp />. One thing I always do is log every request and response, either in a text file, or in a database. That's can be invaluable when troubleshooting.

Hope that helps.

Ciaran Archer
Idea wise it does help definitely; I'm still a little lost with implementation, though. When you say that you can communicate with the API with the cfhttp; does that mean I don't have to go through the extra step of creating and registering a twitter app and a facebook app to jive with the APIs? Can you point me to any sample code? Thanks!
+1  A: 

Use the cffeed tag to pull RSS feeds from Twitter and Facebook. Retain the date of the last feed scan somewhere (application variable or database) and loop over the feed entries. Any entry older than last scan is ignored, everything else gets committed. Make sure to wrap cffeed in a try/catch, as it will throw errors if the service is down (ahem, twitter) As mentioned in other answers, set it up as a scheduled task.

<cffeed action="read" properties="feedMetadata" query="feedQuery"
        source="http://search.twitter.com/search.atom?q=+from:mytwitteraccount" />
lazyconfabulator
Interesting, so you can do it with feeds. I have a few questions about this: 1. how far back in time can you get with this 2. For twitter (since there is only status updates) this seems to work out fine, but with facebook I'd probably need more info than just an RSS feed to (later) copy images and stuff to my system...or are links to a users uploaded images and such somehow accessible from the feed as well? What I'd basically like to do is create a custom aggregator for my own social network stuff, and be able to view all my twitter posts, facebook stuff, uploaded youtube vids, etc.
http://apiwiki.twitter.com/Twitter-Search-API-Method:-searchThe Twitter RSS feed supports a "since" variable that defines how far back you go with your query. I assume the facebook API has similar functionality.
lazyconfabulator
Okay; that's useful. Any idea about the second point? I'll do some digging into the facebook RSS as well. Thanks again.
A: 

Different approach than what you're suggesting, but it worked for us. We had two live events, where we asked people to post to a bespoke Facebook fan page, or to Twitter with a hashtag we endorsed for the event in realtime. Then we just fetched and parsed the RSS feeds of the FB page, and the Twitter search results, extracting what was new, on a short interval... I think it was approximately every three minutes. CFFEED was a little error-prone and wonky, just doing a CFHTTP get of the RSS feeds, and then processing the CFHTTP.filecontent struct item as XML worked fine

.LAG

boycaught