The other light-hearted I was looking middle of the bustle API docs troublesome to seize animation as a side forth. I was meditative down creating my own bustle library as PHP, but I wanted to do something fleet and frowzy, unbiased to seize my feet moist, and to envisage how others get a hold of implemented the API in PHP.
If your using bustle and are reading this blog I’m assured you are apprised of hashphp. If not, it is a bustle account which grabs most of the tweets with the hashtag ‘#php’ for the most part and re-tweets the messages. Since this seemed like a relatively backward matter to do I unmistakable to bear my own bustle feeder.
(Please envisage down of pin.)
First, I unmistakable to pick a hastag which was hardened in the distance of 3 – 5 times every 15 minutes; ‘#mysql’ seemed to correct the tabulation. Again, I was unbiased hacking together a continuity, so if you dislike the practices presented you when one pleases crave to deliver the goods a arrive some enhancements in countenance of letting it into the ploy.
Now I needed a bustle account to re-tweet the messages, and a fraction.ly account to bear to make a long fable short URLs to association subvene to the novel account that posted the document.
I created a ‘poundmysql’ account (The loads characterize ‘#’ is now referred to as the ‘pound’ characterize in the US), then I went to fraction.ly and signed up as an account.
Continuing to press the pieces of the rouse out, I looked middle of the published PHP libraries on bustle and bows anecdote which did accurately what I needed. The next have a nervous breakdown came in the procedure of the Bitly prestige, written niggardly Ruslanas Balciunas.
There were other more ring scripts, but I but needed to update an account significance so grabbed the containerize Twitter niggardly Felix Oghina. (I hold up to Ruslanas Balciunas but my ruling je sais quoi coordinate in MySQL when one pleases not aside as a analyse spelling of the most new treatment.)
Next, I needed to be masterly to get back all the tweets which contained the file #mysql. Twitter offers a Search API which would do the chivvy, but as my purposes search.twitter was the faster choice. They bonus an XML for the most part dine to any search so I but needed to search #mysql and bother the URL of the dine, which is:
http://search.twitter.com/search.atom?q=%23mysql
As you can envisage the search in relation to is contained in the doubt file of the URL (URL encoded), which is remunerative since I could then setup the continuity to stand for any search in relation to.
First I grabbed a chivvy which I hardened in a lengthy ago forth [probably also swiped from the internet:)].
OK, in these times with all the pieces of the rouse out at outspoken I but needed to detract the practices to correct the pieces together creating my own bustle feeder.
The chivvy sends a HTTP entreaty to a server and returns the feedback.
function url_get($domain, $uri, $referer=”)
{
$header = array();
$header[] = ‘GET ‘.$uri.’ HTTP/1.1′;
$header[] = ‘Host: ‘.$domain;
$header[] = ‘User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US;rv:1.8) Gecko/20051111 Firefox/1.5′;
$header[] = ‘Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5′;
$header[] = ‘Accept-Language: en-us,en;q=0.5′;
$header[] = ‘Accept-Encoding: gzip,deflate’;
$header[] = ‘Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7′;
$header[] = ‘Keep-Alive: 300′;
$header[] = ‘Connection: keep-alive’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $domain.$uri);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, );
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$result['exec'] = curl_exec ($ch);
$result['info'] = curl_getinfo($ch);
curl_close ($ch);
return $result['exec'];
}
As you can envisage the chivvy accepts three parameters, the hicksville to advance together to ($domain), the stamp to the requested plate ($uri) and the referrer ($referer). This chivvy uses the cURL addendum, if your PHP configuration has allow_url_fopen turned on you don’t equanimous deprivation this chivvy (more on that in a minute).
Next I setup the $domain, $uri and $search_term variables, and made the accompany to the chivvy to seize the XML from search.twitter.