Zend_Service_Twitter_Search provides a client for the Twitter Search API. The Twitter Search service is use to search Twitter. Currently, it only returns data in Atom or JSON format, but a full REST service is in the future, which will support XML responses.
Returns the top ten queries that are currently trending on Twitter. The response includes the time of the request, the name of each trending topic, and the url to the Twitter Search results page for that topic. Currently the search API for trends only supports a JSON return so the function returns an array.
1 2 3 4 5 6 | $twitterSearch = new Zend_Service_Twitter_Search();
$twitterTrends = $twitterSearch->trends();
foreach ($twitterTrends as $trend) {
print $trend['name'] . ' - ' . $trend['url'] . PHP_EOL
}
|
The return array has two values in it:
Using the search method returns tweets that match a specific query. There are a number of Search Operators that you can use to query with.
The search method can accept six different optional URL parameters passed in as an array:
JSON Search Example
The following code sample will return an array with the search results.
1 2 | $twitterSearch = new Zend_Service_Twitter_Search('json');
$searchResults = $twitterSearch->search('zend', array('lang' => 'en'));
|
ATOM Search Example
The following code sample will return a Zend_Feed_Atom object.
1 2 | $twitterSearch = new Zend_Service_Twitter_Search('atom');
$searchResults = $twitterSearch->search('zend', array('lang' => 'en'));
|
While the Twitter Search API only specifies two methods, Zend_Service_Twitter_Search has additional methods that may be used for retrieving and modifying internal properties.
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.