Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude Retweets in Twitter Search API 1.1

Tags:

Here I'm trying to retrieve the tweets which has the tag 'V57' using search api 1.1. Dumped & seen the results of search term by using,

$search_tim = $connection->get('search/tweets',array('q' => ' #V57', 'count' => 5, 'result_type' => 'recent'));

This is the result after doing var_dump :

object(stdClass)#10 (2) { ["statuses"]=>  array(5) { [0]=> object(stdClass)#11 (25) {   ["metadata"]=>   object(stdClass)#12 (2) {     ["result_type"]=>     string(6) "recent"     ["iso_language_code"]=>     string(2) "en"   }   ["created_at"]=>   string(30) "Wed Feb 12 16:26:35 +0000 2014"   ["id"]=>   float(4.33638273555E+17)   ["id_str"]=>   string(18) "4336382731354561"   ["text"]=>   string(131) "RT @useracc: Plz consult a doctor #V57"   ["source"]=>   string(84) "Twitter for Android"   ["truncated"]=>   bool(false)   ["in_reply_to_status_id"]=>   NULL   ["in_reply_to_status_id_str"]=>   NULL   ["in_reply_to_user_id"]=>   NULL   ["in_reply_to_user_id_str"]=>   NULL   ["in_reply_to_screen_name"]=>   NULL   ["user"]=>   object(stdClass)#13 (40) {     ["id"]=>     int(965892252)     ["id_str"]=>     string(9) "965892252"     ["name"]=>     string(10) "khan"     ["screen_name"]=>     string(10) "khan"     ["location"]=>     string(0) ""      ["url"]=>     NULL     ["entities"]=>     object(stdClass)#14 (1) {       ["description"]=>       object(stdClass)#15 (1) {         ["urls"]=>         array(0) {         }       }     }     ["protected"]=>     bool(false)     ["followers_count"]=>     int(457)     ["friends_count"]=>     int(500)     ["listed_count"]=>     int(3)     ["created_at"]=>     string(30) "Fri Nov 23 10:56:08 +0000 2012"     ["favourites_count"]=>     int(129)     ["utc_offset"]=>     int(19800)     ["time_zone"]=>     string(7) "Chennai"     ["geo_enabled"]=>     bool(false)     ["verified"]=>     bool(false)     ["statuses_count"]=>     int(3230)     ["lang"]=>     string(2) "en"     ["contributors_enabled"]=>     bool(false)     ["is_translator"]=>     bool(false)     ["is_translation_enabled"]=>     bool(false)     ["profile_background_color"]=>     string(6) "0099B9"     ["profile_background_image_url"]=>     string(48) "http://abs.twimg.com/images/themes/theme4/bg.gif"     ["profile_background_image_url_https"]=>     string(49) "https://abs.twimg.com/images/themes/theme4/bg.gif"     ["profile_background_tile"]=>     bool(false)     ["profile_image_url"]=>     string(99) "http://pbs.twimg.com/profile_images/3788093993/0639a4b8297f9eea2cbb9de89f5c3a40_normal.jpeg"     ["profile_image_url_https"]=>     string(100) "https://pbs.twimg.com/profile_images/37883993/0639a4b8297f9eea2cbb95c3a40_normal.jpeg"     ["profile_banner_url"]=>     string(58) "https://pbs.twimg.com/profile_banners/9658922/1386619"     ["profile_link_color"]=>     string(6) "0099B9"     ["profile_sidebar_border_color"]=>     string(6) "5ED4DC"     ["profile_sidebar_fill_color"]=>     string(6) "95E8EC"     ["profile_text_color"]=>     string(6) "3C3940"     ["profile_use_background_image"]=>     bool(true)     ["default_profile"]=>     bool(false)     ["default_profile_image"]=>     bool(false)     ["following"]=>     bool(false)     ["follow_request_sent"]=>     bool(false)     ["notifications"]=>     bool(false)   }   ["geo"]=>   NULL   ["coordinates"]=>   NULL   ["place"]=>   NULL   ["contributors"]=>   NULL   ["retweeted_status"]=>   object(stdClass)#16 (24) {     ["metadata"]=>     object(stdClass)#17 (2) {       ["result_type"]=>       string(6) "recent"       ["iso_language_code"]=>       string(2) "en"     }     ["created_at"]=>     string(30) "Wed Feb 12 15:33:36 +0000 2014"     ["id"]=>     float(4.3362493936345E+17)     ["id_str"]=>     string(18) "43362493446784"     ["source"]=>     string(84) "Twitter for Android"     ["truncated"]=>     bool(false)     ["in_reply_to_status_id"]=>     NULL     ["in_reply_to_status_id_str"]=>     NULL     ["in_reply_to_user_id"]=>     NULL     ["in_reply_to_user_id_str"]=>     NULL     ["in_reply_to_screen_name"]=>     NULL     ["user"]=>     object(stdClass)#18 (40) {       ["id"]=>       int(168362964)       ["id_str"]=>       string(9) "168362964"       ["name"]=>       string(5) "usracc"       ["screen_name"]=>       string(12) "useracc"       ["location"]=>       string(16) "India."       ["url"]=>       NULL       ["entities"]=>       object(stdClass)#19 (1) {         ["description"]=>         object(stdClass)#20 (1) {           ["urls"]=>           array(0) {           }         }       }       ["protected"]=>       bool(false)       ["followers_count"]=>       int(651)       ["friends_count"]=>       int(197)       ["listed_count"]=>       int(6)       ["created_at"]=>       string(30) "Mon Jul 19 03:54:15 +0000 2010"       ["favourites_count"]=>       int(4267)       ["utc_offset"]=>       int(19800)       ["time_zone"]=>       string(7) "Chennai"       ["geo_enabled"]=>       bool(true)       ["verified"]=>       bool(false)       ["statuses_count"]=>       int(10177)       ["lang"]=>       string(2) "en"       ["contributors_enabled"]=>       bool(false)       ["is_translator"]=>       bool(false)       ["is_translation_enabled"]=>       bool(false)       ["profile_background_color"]=>       string(6) "C0DEED"       ["profile_background_image_url"]=>       string(48) "http://abs.twimg.com/images/themes/theme1/bg.png"       ["profile_background_image_url_https"]=>       string(49) "https://abs.twimg.com/images/themes/theme1/bg.png"       ["profile_background_tile"]=>       bool(false)       ["profile_image_url"]=>       string(75) "http://pbs.twimg.com/profile_images/4338561184/quFHKeYq_normal.jpeg"       ["profile_image_url_https"]=>       string(76) "https://pbs.twimg.com/profile_images/433856131184/quFHKeYq_normal.jpeg"       ["profile_banner_url"]=>       string(58) "https://pbs.twimg.com/profile_banners/168364/1392170036"       ["profile_link_color"]=>       string(6) "0084B4"       ["profile_sidebar_border_color"]=>       string(6) "C0DEED"       ["profile_sidebar_fill_color"]=>       string(6) "DDEEF6"       ["profile_text_color"]=>       string(6) "333333"       ["profile_use_background_image"]=>       bool(true)       ["default_profile"]=>       bool(true)       ["default_profile_image"]=>       bool(false)       ["following"]=>       bool(false)       ["follow_request_sent"]=>       bool(false)       ["notifications"]=>       bool(false)     }     ["geo"]=>     NULL     ["coordinates"]=>     NULL     ["place"]=>     NULL     ["contributors"]=>     NULL     ["retweet_count"]=>     int(5)     ["favorite_count"]=>     int(10)     ["entities"]=>     object(stdClass)#21 (5) {       ["hashtags"]=>       array(1) {         [0]=>         object(stdClass)#22 (2) {           ["text"]=>           string(7) "v57"           ["indices"]=>           array(2) {             [0]=>             int(76)             [1]=>             int(84)           }         }       }       ["symbols"]=>       array(0) {       }       ["urls"]=>       array(0) {       }               ["favorited"]=>     bool(false)     ["retweeted"]=>     bool(false)     ["possibly_sensitive"]=>     bool(false)     ["lang"]=>     string(2) "en"   }   ["retweet_count"]=>   int(5)   ["favorite_count"]=>   int(0) 

Now, i would like to retrieve the original tweets alone which has V57 tag by ignoring all Retweets similar to this

string(131) "RT @useravv: Plz consult a doctor #V57"

I've googled and found this thread. But it was old API version.

My Doubt has been cleared. Thanks to the SO user Newbi3 :)

Here is a way to exclude Retweets in Search api 1.1

$search_tim = $connection->get('search/tweets',array('q' => ' #V57 -RT', 'count' => 5,'result_type' => 'recent')); 

Adding -RT at the end of search term will filter it.

EDIT :

The above approach will simply eliminate the tweet too if they included #RT is in their status and username or screename. This will blindly ignore tweets when its sees RT. This is a temporary solution.

The permanent solution is, get the RT status & if if its retweet simply assign a value like 1 to a variable & 0 if its original. Eg..

    if (isset($tweet_object->retweeted_status)) {   // This is a retweet   // Use the original tweet's entities, they are more complete   $entities = $tweet_object->retweeted_status->entities;         $is_rt = 1; // Set 1 if retweeted   } else {       $entities = $tweet_object->entities;       $is_rt = 0; // Set 0 if original   } 

Then just do like,

if($is_rt==0) // if its a original tweet {   ...   .... } 
like image 806
user3289108 Avatar asked Feb 13 '14 08:02

user3289108


1 Answers

I have found concatenating "-filter:retweets" to the end of your query string works best.

If you simply add -RT you might run into issues with accidentally filtering tweets containing "RT" for example "Russia Today" will use that string quite a lot!

The following pages describe Twitter search operators:

  • https://support.twitter.com/articles/71577-using-advanced-search
  • http://thesocialchic.com/2013/04/26/how-to-master-twitter-search/
like image 68
Alexander McFarlane Avatar answered Oct 13 '22 19:10

Alexander McFarlane