Please support the "search" method

lyricnz - September 22, 2009 - 13:47
Project:Twitter
Version:6.x-3.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

http://apiwiki.twitter.com/Twitter-Search-API-Method%3A+search

#1

auzigog - September 23, 2009 - 02:58

I would absolutely love to see this as well. I love everything about the twitter module. Adding this feature would really complete it's feature set.

Thanks!

#2

Flplsx - September 30, 2009 - 18:09

This feature would bring the module into a whole new class of awesome!

#3

lyricnz - October 1, 2009 - 09:12

The (not insurmountable) problems are:
- search uses a separate URL http://search.twitter.com
- the results are not the the same format as other methods in the same API, requiring unique theming/presentation

That being said, I'm using the following code in one of my modules:

<?php
/**
* Implement the "search" method from Twitter.
*
* @see <a href="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A+search
" title="http://apiwiki.twitter.com/Twitter-Search-API-Method%3A+search
" rel="nofollow">http://apiwiki.twitter.com/Twitter-Search-API-Method%3A+search
</a> */
function mymodules_twitter_search($query, $rpp = 10) {
 
module_load_include('inc', 'twitter');

 
$url = 'http://search.twitter.com/search.atom?q=' . urlencode($query);
 
$url .= "&rpp=$rpp";
 
 
// $response = _mymodule_twitter_fetch_xml($url); // drupal_http_request() + status check + caching
  // roughly equivalent to:
 
$results = drupal_http_request($url);
 
$response = $results->data;

 
// Process the response
 
$tweets = array();
 
$xml = simplexml_load_string($response);
  if (
$xml) {
   
// Add search metadata
   
$tweets['metadata'] = array(
     
'id' => (string) $xml->id,
     
'title' => (string) $xml->title,
     
'link' => (string) $xml->link[0]['href'],
     
'updated' => (string) $xml->updated,
     
'query' => $query,
    );
   
// Add individual tweets
   
foreach ($xml->entry as $entry) {
     
$tbits = $entry->children('twitter', TRUE);
     
$tweets[] = array(
       
'id' => (string) $entry->id,
       
'published' => (string) $entry->published,
       
'link' => (string) $entry->link[0]['href'],
       
'title' => (string) $entry->title,
       
'content' => (string) $entry->content,
       
'updated' => (string) $entry->updated,
       
'image' => (string) $entry->link[1]['href'],
       
'source' => (string) $tbits[0],
       
'lang' => (string) $tbits[1],
       
'author name' => (string) $entry->author->name,
       
'author uri' => (string) $entry->author->uri,
       
'xml' => $entry->asXML(),
      );
    }
  }
  else {
   
drupal_set_message('Cannot load XML: '. $url, 'error');
  }

  return
$tweets;
}
?>

This probably doesn't support ALL the ways results can arrive (multiple links, images, etc), but works pretty well for me. If module maintainer is interested in adding search to twitter, this might be a useful start.

#4

abraham - October 1, 2009 - 09:40
Version:6.x-2.6» 6.x-3.x-dev

Twitter is planning on unifying the data objects on their REST and Search APIs sometime this year: http://apiwiki.twitter.com/FAQ#AreyougoingtomaketheRESTAPIandtheSearchAP...

#5

KevinHerrington - October 1, 2009 - 17:32

Here's a patch that's been working well for me. It adds a field for a global search string on the admin/settings/twitter page.

---
Developed by ActiveLAMP, sponsored by Causecast

AttachmentSize
twitter_search_support.patch 4.89 KB

#6

bdwelle - October 5, 2009 - 14:23

+1 on this feature

I installed the patch and it seems to work fine.

thx!

#7

dragonwize - November 10, 2009 - 18:43

I've created a module using some of the ideas and code here with some additions and modifications of my own. It still needs a little work and more testing. Volunteers welcome: http://drupal.org/project/twitter_search

#8

sirkitree - December 3, 2009 - 00:34
Status:active» needs review

Marking as needs review.

 
 

Drupal is a registered trademark of Dries Buytaert.