Link to home
Start Free TrialLog in
Avatar of ckryanco
ckryanco

asked on

How to use ColdFusion to connect to Twitter's new streaming API

Is it possible to connect to the new Twitter streaming API using ColdFusion?

I'm referring to the service documented here: http://dev.twitter.com/pages/streaming_api

I've been able to connect to it using curl.exe and a batch file and data file (see below). Is it possible to get ColdFusion to do the same thing, just capturing the JSON data that's being sent? Once it's captured, it should be easy enough to de-serialize the JSON with CF functions and go to town.

Test.bat: (replace "AnyTwitterAccount:Password" with a twitter account and password)

curl -d @following.txt http://stream.twitter.com/1/statuses/filter.json -u AnyTwitterAccount:Password


following.txt:

follow=12,13,15,16,20,87,48811565,7021362

I'm looking for the mechanism to establish the connection, and capture the JSON data that streams through. After that, no problem.

Many thanks!
Avatar of Mr_Nil
Mr_Nil
Flag of United Kingdom of Great Britain and Northern Ireland image

You need to use a client that can handle streaming data.  See here for connecting to the streaming api: http://dev.twitter.com/pages/streaming_api_concepts#connecting

A quick look at the curl documentation didn't seem to suggestion either way whether it is or isn't capable of handling streaming data in this fashion.

The streaming API would be more useful on the client side and not on the server side.  eg. making a persistent AJAX connection to stream content into a div on a web page (as a simplistic example)

Server side access to twitter you would be better sticking to the standard API and using CFHTTP or CFINVOKE to make request to the API. If you need help with that - take a look at http://riaforge.org/ There are at least 3 twitter APIs for ColdFusion on there.
Avatar of ckryanco
ckryanco

ASKER

Thanks. The standard Twitter API works perfectly -- but the 150-requests-per-hour rate limit imposed by Twitter applies there (so a Twitter staffer suggested the streaming API, since it isn't rate-limited, for now at least...)

There's no obvious way to to use ColdFusion to maintain a streaming http connection, and I don't want to install a whole new development platform like PHP or Python (which can do this), just for this one project.

Hence the question about whether there's a way to accomplish this in ColdFusion. Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Mr_Nil
Mr_Nil
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks again. The Twitter staffer suggested it after we applied for whitelisting, saying that Twitter is being "VERY stingy" about granting whitelisting these days because their system has been running so close to capacity for so long. (We still officially haven't heard back from Twitter about our whitelisting application...)

The streaming API was suggested as a possible way around the rate-limiting problem. But it's sure looking ugly... (This is for an application for news websites that captures tweets from groups of selected Twitter accounts of broad community interest, stores them on the local servers, and automatically posts them directly on the news websites -- such as all the Tweets from the local city/county governments.) It works perfectly using the standard Twitter API -- but Twitter won't even consider whitelisting unless the application is in production. Grrrrr....

Have you tried "just" replacing the calls to the normal api with cfhttp calls to the streaming api, treating it as if it were a normal REST api rather than a streaming API.  It might work...

You probably need to thread the requests and give them a 30 second timeout with a fall back to some previously stored data if you don't get anything back. That kind of thing.

Just a thought that went through my mind... probably holds no water...