Monday, December 1, 2014

Twitter API Requests for Twitter Feeds using JS (client side)

I was trying to build out a tool that would show twitter feeds for a given user.  I did the usual and searched google for baked out solutions that I could drop in and tweak as I see fit.  That didn't return any immediate results so I dove into playing with codebird.js and found some success, but was still struggling with wrapping my head around the oauth options and what I was able to query.

I had to step away from the computer for a while, but an hour later I returned and went back to the google search to see if I could find someone else who'd had a similar problem.  That's when I found Jason Mayes solution (here).  It seemed perfect!  The reasons he built it were for the same reasons that I went searching for it.  AWESOME.

So implemented it and quickly discovered this tool wouldn't be a solution for a business that needs to produce more than a handful of twitter feeds (plenty of people trying to do that here)  So after seeing that I'd have to create a widget for each feed I wanted to create and that would most likely have to be done manually I decided that the official API was the best route to go down.

So here is how I did it....

1) Get codebird.js (here)
2) Include it in your HTML
3) Add this JS and replace the needed fields:

var cb = new Codebird;
cb.setConsumerKey("key", "secret");
var params = { screen_name: "username", count: 20 };
cb.__call( 
 "statuses_userTimeline",
 params,
 function (reply) { 
   console.log(reply);
   // Do stuff...
});

Wa-la.  I think what I need next is some help blogging.  I hope this helps someone who needs a quick fix.

No comments:

Post a Comment