PEAR’s Services_Twitter and the Source Option
I recently started using PEAR’s Services_Twitter package (still in beta) written by Joe Stump (from Digg) and David Jean Louis. My natural choice would have been Zend Framework’s Zend_Service_Twitter, but I wasn’t aware that it was out of the incubator by the time I started.
Using and integrating the Services_Twitter package was very easy, and didn’t require much more than copying and pasting the code from the class documentation:
require_once 'Services/Twitter.php'; $username = 'You_Username'; $password = 'Your_Password'; try { $twitter = new Services_Twitter($username, $password); $msg = $twitter->statuses->update("I'm coding with PEAR right now!"); print_r($msg); // Should be a SimpleXMLElement structure } catch (Services_Twitter_Exception $e) { echo $e->getMessage(); }
However, once I requested the “source” option from twitter (that nifty thing that says where the tweet was sent via), things got complicated. Apparently, when the Twitter.php factory builds an instance of an API driver, it instantiates a new object, and doesn’t pass it the current factory options, so this didn’t work:
$twitter = new Services_Twitter($username, $password); $twitter->setOptions('source','myapp'); $msg = $twitter->statuses->update("I'm coding with PEAR right now!"); print_r($msg); // Should be a SimpleXMLElement structure
The status was updated, but with no source. A short debug and look through the source revealed that factory behavior (not passing the current options to the newly instantiated statuses object). I don’t really see the rationale behind this, so I filed a bug report.
What did work, was instantiating a Twitter_Statuses object, and working with it directly, like this:
include_once "Services/Twitter/Statuses.php"; $twitter = new Services_Twitter_Statuses($username, $password); $twitter->setOptions('source','myapp'); $msg = $twitter->update("I'm coding with PEAR right now!");
Now you can Tweet away with source!
About this entry
You’re currently reading “PEAR’s Services_Twitter and the Source Option,” an entry on Life Scaling
- Published:
- 1.13.09 / 2pm
- Category:
- LAMP
- Tags:
- PEAR, PHP, Services_Twitter, source, Twitter
Follow me on Twitter: @orensol
- Hey #AWS, how about improving EBS? Maybe change underlying hardware to SSD, and make it more predictable? http://j.mp/gRG2b9
- @sebastianstadil it is indeed beautiful. It really depends on your use case and space to put it. I don't like when a printer crowds my desk.
- @sebastianstadil get one with builtin wifi (like hp1102w). Then you can throw it off wherever it fits around the house/office.
- Facebook Engineering Blog is one of the most incredible things to read on the Internet. http://j.mp/e7gFjg
- @dvirsky hehe, I read it as two different girlfriends, which made your tweet much more heart warming.

I am Oren, and this is my blog. I am a techie entrepreneur, co-founder & CTO of
No comments
Jump to comment form | comments rss [?] | trackback uri [?]