A really quick, no API, Zend_Service_Twitter example

Leave a comment

One of the cool things in Zend Framework is the Zend_Service layer.  What it basically does is provide access to a variety of different service-based… well, services, so that you can easily integrate your application with other services.  One example is, of course, Twitter.  Often, to connect to various services you need to have an API key that you use to connect.  The same is true for Twitter, except for public feed information.  What this means is that you can search Twitter for free, with no API, easily.

I will assume that you are using the Autoloader.  Pretty much all of my scripts start with this.

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

So, to do a quick, API-free Twitter search:

$jobs = $notAnnoying = 0;
$ts = new Zend_Service_Twitter_Search('json');
$sr = $ts->search('#php');
foreach (array_shift($sr) as $res) {

if (strpos($res[‘text’], ‘#job’) === false
&& strpos($res[‘text’], ‘#free’) === false) {
$notAnnoying++;
echo ‘:) ‘;
} else {
$jobs++;
echo ‘:( ‘;
}

echo $res[‘text’] . “<Br />”;
}
echo “<br />”;
echo “Not Annoying: {$notAnnoying}<br />”;
echo “Jobs Posting: {$jobs}<br />”;

The output for this is

 

:) finally, #ZCE exam scheduled for Fri, 5 Mar 2010 at 10:00am #zend #php
:) #php User Manager updated, fixing email issues; http://bit.ly/cId3Uc
:( We're hiring. Full-time PHP Developer. You got the goods? - http://twurl.nl/6of5oj - #job #hiring #php #webdev #fb
:( We're hiring. Full-time PHP Developer. You got the goods? - http://twurl.nl/6of5oj - #job #hiring #php #webdev #fb
:) Suche einen #Programmierer, der sich mit #HTML, #PHP und #Ajax auskennt (2010-03-23 Berlin) http://bit.ly/d0aZAw
:) #php Surviving Web site traffic peaks. http://tinyurl.com/yf7qhc7
:) $bool = (0 == 'aaa'); // これがtrueになるってどういう仕様だよ #php
:( Looking to hire 2 Web Developers for #Wordpress projects, #PHP http://bit.ly/asWaRx & #CSS http://bit.ly/c5WA71 #jobs call/text 858 254 9711
:) http://guwi.com.au We're now available for freelance webdesign and development work. #css #php #javascript
:( #php #freelance Rotating Banner PHP Script by shetlandpony: Recently I hired a person to upgrade my Invision forum... http://bit.ly/9Cly9z
:( #php #freelance File Sharing Script by kusoftware: I'm looking for a script where people can upload files and shar... http://bit.ly/aopLRz
:( #php #freelance Drupal site - Corrections and items needed by nearsource: We have a Drupal site from a client. ... http://bit.ly/ctkX3F
:( #php #freelance Nonpublic project #620248 by fraserbsquared: The project is Nonpublic. Description can be read onl... http://bit.ly/di26q0
:( #php #freelance Scrape website stats 2 with myboot by koolego2: *This is a private invite project only* Require... http://bit.ly/aLRrK5
:( #php #freelance Rotating Banner PHP Script by shetlandpony: Recently I hired a person to upgrade my Invision forum... http://bit.ly/9Cly9z

Not Annoying: 6
Jobs Posting: 9

Easy

Leave a Reply

Your email address will not be published. Required fields are marked *