Skip to content

Accessing Twitter via Zend_Service_Twitter

Dear Reader,

Ok, I know there are a lot of OAuth haters out there and maybe it is not the easiest protocol to work with but really, I was able to get connected and running in about 15 minutes. (and that included 5 minutes of Google time)

The Project

I am playing around with Klout’s API and wanted to pull in some info from twitter to augment the Klout info I was seeing. Klout is easy – as just about every Mashery API I’ve worked with has been – you just register for a key and they make your calls. Twitter however, requires OAuth. I knew the Zend_Service_Twitter had recently undergone a revamp to support OAuth but there was one small problem. The script I am playing with is all backend. There is no front end at all. It just collects info and stores it in a database so I can query it later. (I’m an old-school database guy and love just writing ad-hoc queries to see what I can see) Twitter wants to redirect you to a site once you have authorized access. Since I don’t actually have a site to redirect it to, this was a problem.

The Solution – in two parts.

Ok, second things first, this script is straight procedural code at the moment. It isn’t even good enough to qualify as prototype code, more proof-of-concept. There’s no way in heck I’m sharing it with anyone so don’t even ask. I know, however that if things progress as I expect them to, the script will end up as a Zend Framework application. For that reason I wanted to use Zend_Service_Twitter. A quick Google showed me that my good friend and Zend Framework community member Michelangelo van Dam had a tutorial already written on this very subject titled Single User Zend_Service_Twitter. Part 2 is solved because everything I need to know is in that tutorial. So I move on to the first problem, how to get a valid OAuth token and secret. It turns out, that wasn’t hard at all either, it just required a little imagination.

Jaisen Mathai wrote up a blog post titled Twitter, PHP and OAuth a little while back explaining OAuth. In it he links to a quick piece of sample code that he put together to showcase his Twitter API wrapper. The wrapper itself is good and if I had not already decided to go with Zend Framework, I would have used it. The sample code however, allowed me to authenticate with twitter and then store the token and secret, the two things you must have to make this work. So I took his sample code, put it on my development server, followed his instructions to the letter and voilà, I had my token and and token secret.

I then went back to Dragonbe’s blog post, grabbed his code, modified it slightly so that I didn’t have to use Zend_Config and it worked too!


If you want to get started with Twitter’s OAuth, the two tutorials I’ve linked to are great jumping off points. Enjoy!

Until next time,
I <3 |<

Photo Credit:erikeldridge

Update from webcast on Zend_Cache_Frontend_Class

Dear Reader,

In reading over the chat room log for my recent webcast, Zend Framework: Piece by Piece I noticed a question from my buddy Elazar about Zend_Cache_Frontend_Class. Thinking I had made a mistake, I reviewed the materials and the Zend_Cache_Frontend_Class documentation page so that I could do a quick update. The answer wasn’t nearly as simple as I thought.

Quickie Zend Framework Bootstrap Note

Dear Reader,

I’ve been teaching a Zend Framework class this week and my students have been throwing all kinds of questions at me. Most recently, while we were discussing creating a Bootstrap class for an application a question came up about the _init* functions.

The manual states that


will fire all of the _init* functions in the bootstrap class. However, the question came up, in what order? Thanks to friends like Rob Allen (author of “Zend Framework in Action“), I was able to give them the answer.


Things I learned about Zend Tool

Dear Reader,

I’m prepping some training on Zend Framework and have been working with Zend Tool a lot. When MWOP first told me about Zend_Tool, I thought cool. and when it hit the incubator, I grabbed it. I followed the two hour install instructions…then did it again, because I missed a step. Finally I had it and zf show version didn’t throw an error. However, everything else did. It pretty much sucked.