title: Exclude Retweets in Twitter Search API 1.1
body: <p>Here I'm trying to retrieve the tweets which has the tag 'V57' using search api 1.1. Dumped &amp; seen the results of search term by using,</p>
  
  <p><code>$search_tim = $connection-&gt;get('search/tweets',array('q' =&gt; ' #V57', 'count' =&gt; 5, 'result_type' =&gt; 'recent'));</code></p>
  
  <p>This is the result after doing <strong>var_dump</strong> :</p>
  
  <pre><code>object(stdClass)#10 (2) {
  ["statuses"]=&gt;
   array(5) {
  [0]=&gt;
  object(stdClass)#11 (25) {
    ["metadata"]=&gt;
    object(stdClass)#12 (2) {
      ["result_type"]=&gt;
      string(6) "recent"
      ["iso_language_code"]=&gt;
      string(2) "en"
    }
    ["created_at"]=&gt;
    string(30) "Wed Feb 12 16:26:35 +0000 2014"
    ["id"]=&gt;
    float(4.33638273555E+17)
    ["id_str"]=&gt;
    string(18) "4336382731354561"
    ["text"]=&gt;
    string(131) "RT @useracc: Plz consult a doctor #V57"
    ["source"]=&gt;
    string(84) "Twitter for Android"
    ["truncated"]=&gt;
    bool(false)
    ["in_reply_to_status_id"]=&gt;
    NULL
    ["in_reply_to_status_id_str"]=&gt;
    NULL
    ["in_reply_to_user_id"]=&gt;
    NULL
    ["in_reply_to_user_id_str"]=&gt;
    NULL
    ["in_reply_to_screen_name"]=&gt;
    NULL
    ["user"]=&gt;
    object(stdClass)#13 (40) {
      ["id"]=&gt;
      int(965892252)
      ["id_str"]=&gt;
      string(9) "965892252"
      ["name"]=&gt;
      string(10) "khan"
      ["screen_name"]=&gt;
      string(10) "khan"
      ["location"]=&gt;
      string(0) ""
  
      ["url"]=&gt;
      NULL
      ["entities"]=&gt;
      object(stdClass)#14 (1) {
        ["description"]=&gt;
        object(stdClass)#15 (1) {
          ["urls"]=&gt;
          array(0) {
          }
        }
      }
      ["protected"]=&gt;
      bool(false)
      ["followers_count"]=&gt;
      int(457)
      ["friends_count"]=&gt;
      int(500)
      ["listed_count"]=&gt;
      int(3)
      ["created_at"]=&gt;
      string(30) "Fri Nov 23 10:56:08 +0000 2012"
      ["favourites_count"]=&gt;
      int(129)
      ["utc_offset"]=&gt;
      int(19800)
      ["time_zone"]=&gt;
      string(7) "Chennai"
      ["geo_enabled"]=&gt;
      bool(false)
      ["verified"]=&gt;
      bool(false)
      ["statuses_count"]=&gt;
      int(3230)
      ["lang"]=&gt;
      string(2) "en"
      ["contributors_enabled"]=&gt;
      bool(false)
      ["is_translator"]=&gt;
      bool(false)
      ["is_translation_enabled"]=&gt;
      bool(false)
      ["profile_background_color"]=&gt;
      string(6) "0099B9"
      ["profile_background_image_url"]=&gt;
      string(48) "http://abs.twimg.com/images/themes/theme4/bg.gif"
      ["profile_background_image_url_https"]=&gt;
      string(49) "https://abs.twimg.com/images/themes/theme4/bg.gif"
      ["profile_background_tile"]=&gt;
      bool(false)
      ["profile_image_url"]=&gt;
      string(99) "http://pbs.twimg.com/profile_images/3788093993/0639a4b8297f9eea2cbb9de89f5c3a40_normal.jpeg"
      ["profile_image_url_https"]=&gt;
      string(100) "https://pbs.twimg.com/profile_images/37883993/0639a4b8297f9eea2cbb95c3a40_normal.jpeg"
      ["profile_banner_url"]=&gt;
      string(58) "https://pbs.twimg.com/profile_banners/9658922/1386619"
      ["profile_link_color"]=&gt;
      string(6) "0099B9"
      ["profile_sidebar_border_color"]=&gt;
      string(6) "5ED4DC"
      ["profile_sidebar_fill_color"]=&gt;
      string(6) "95E8EC"
      ["profile_text_color"]=&gt;
      string(6) "3C3940"
      ["profile_use_background_image"]=&gt;
      bool(true)
      ["default_profile"]=&gt;
      bool(false)
      ["default_profile_image"]=&gt;
      bool(false)
      ["following"]=&gt;
      bool(false)
      ["follow_request_sent"]=&gt;
      bool(false)
      ["notifications"]=&gt;
      bool(false)
    }
    ["geo"]=&gt;
    NULL
    ["coordinates"]=&gt;
    NULL
    ["place"]=&gt;
    NULL
    ["contributors"]=&gt;
    NULL
    ["retweeted_status"]=&gt;
    object(stdClass)#16 (24) {
      ["metadata"]=&gt;
      object(stdClass)#17 (2) {
        ["result_type"]=&gt;
        string(6) "recent"
        ["iso_language_code"]=&gt;
        string(2) "en"
      }
      ["created_at"]=&gt;
      string(30) "Wed Feb 12 15:33:36 +0000 2014"
      ["id"]=&gt;
      float(4.3362493936345E+17)
      ["id_str"]=&gt;
      string(18) "43362493446784"
      ["source"]=&gt;
      string(84) "Twitter for Android"
      ["truncated"]=&gt;
      bool(false)
      ["in_reply_to_status_id"]=&gt;
      NULL
      ["in_reply_to_status_id_str"]=&gt;
      NULL
      ["in_reply_to_user_id"]=&gt;
      NULL
      ["in_reply_to_user_id_str"]=&gt;
      NULL
      ["in_reply_to_screen_name"]=&gt;
      NULL
      ["user"]=&gt;
      object(stdClass)#18 (40) {
        ["id"]=&gt;
        int(168362964)
        ["id_str"]=&gt;
        string(9) "168362964"
        ["name"]=&gt;
        string(5) "usracc"
        ["screen_name"]=&gt;
        string(12) "useracc"
        ["location"]=&gt;
        string(16) "India."
        ["url"]=&gt;
        NULL
        ["entities"]=&gt;
        object(stdClass)#19 (1) {
          ["description"]=&gt;
          object(stdClass)#20 (1) {
            ["urls"]=&gt;
            array(0) {
            }
          }
        }
        ["protected"]=&gt;
        bool(false)
        ["followers_count"]=&gt;
        int(651)
        ["friends_count"]=&gt;
        int(197)
        ["listed_count"]=&gt;
        int(6)
        ["created_at"]=&gt;
        string(30) "Mon Jul 19 03:54:15 +0000 2010"
        ["favourites_count"]=&gt;
        int(4267)
        ["utc_offset"]=&gt;
        int(19800)
        ["time_zone"]=&gt;
        string(7) "Chennai"
        ["geo_enabled"]=&gt;
        bool(true)
        ["verified"]=&gt;
        bool(false)
        ["statuses_count"]=&gt;
        int(10177)
        ["lang"]=&gt;
        string(2) "en"
        ["contributors_enabled"]=&gt;
        bool(false)
        ["is_translator"]=&gt;
        bool(false)
        ["is_translation_enabled"]=&gt;
        bool(false)
        ["profile_background_color"]=&gt;
        string(6) "C0DEED"
        ["profile_background_image_url"]=&gt;
        string(48) "http://abs.twimg.com/images/themes/theme1/bg.png"
        ["profile_background_image_url_https"]=&gt;
        string(49) "https://abs.twimg.com/images/themes/theme1/bg.png"
        ["profile_background_tile"]=&gt;
        bool(false)
        ["profile_image_url"]=&gt;
        string(75) "http://pbs.twimg.com/profile_images/4338561184/quFHKeYq_normal.jpeg"
        ["profile_image_url_https"]=&gt;
        string(76) "https://pbs.twimg.com/profile_images/433856131184/quFHKeYq_normal.jpeg"
        ["profile_banner_url"]=&gt;
        string(58) "https://pbs.twimg.com/profile_banners/168364/1392170036"
        ["profile_link_color"]=&gt;
        string(6) "0084B4"
        ["profile_sidebar_border_color"]=&gt;
        string(6) "C0DEED"
        ["profile_sidebar_fill_color"]=&gt;
        string(6) "DDEEF6"
        ["profile_text_color"]=&gt;
        string(6) "333333"
        ["profile_use_background_image"]=&gt;
        bool(true)
        ["default_profile"]=&gt;
        bool(true)
        ["default_profile_image"]=&gt;
        bool(false)
        ["following"]=&gt;
        bool(false)
        ["follow_request_sent"]=&gt;
        bool(false)
        ["notifications"]=&gt;
        bool(false)
      }
      ["geo"]=&gt;
      NULL
      ["coordinates"]=&gt;
      NULL
      ["place"]=&gt;
      NULL
      ["contributors"]=&gt;
      NULL
      ["retweet_count"]=&gt;
      int(5)
      ["favorite_count"]=&gt;
      int(10)
      ["entities"]=&gt;
      object(stdClass)#21 (5) {
        ["hashtags"]=&gt;
        array(1) {
          [0]=&gt;
          object(stdClass)#22 (2) {
            ["text"]=&gt;
            string(7) "v57"
            ["indices"]=&gt;
            array(2) {
              [0]=&gt;
              int(76)
              [1]=&gt;
              int(84)
            }
          }
        }
        ["symbols"]=&gt;
        array(0) {
        }
        ["urls"]=&gt;
        array(0) {
        }          
      ["favorited"]=&gt;
      bool(false)
      ["retweeted"]=&gt;
      bool(false)
      ["possibly_sensitive"]=&gt;
      bool(false)
      ["lang"]=&gt;
      string(2) "en"
    }
    ["retweet_count"]=&gt;
    int(5)
    ["favorite_count"]=&gt;
    int(0)
  </code></pre>
  
  <p>Now, i would like to retrieve the original tweets alone which has <code>V57</code> tag by ignoring all Retweets similar to this </p>
  
  <p><code>string(131) "RT @useravv: Plz consult a doctor #V57"</code></p>
  
  <p>I've googled and found this <a href="https://stackoverflow.com/questions/7400656/twitter-search-atom-api-exclude-retweets">thread</a>. But it was old API version.</p>
  
  <p><strong>My Doubt has been cleared. Thanks to the SO user Newbi3</strong> :)</p>
  
  <p>Here is a way to exclude Retweets in Search api 1.1</p>
  
  <pre><code>$search_tim = $connection-&gt;get('search/tweets',array('q' =&gt; ' #V57 -RT', 'count' =&gt; 5,'result_type' =&gt; 'recent'));
  </code></pre>
  
  <p>Adding -RT at the end of <code>search term</code> will filter it.</p>
  
  <p><strong>EDIT :</strong> </p>
  
  <p>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.</p>
  
  <p>The permanent solution is, get the RT status &amp; if if its retweet simply assign a value like 1 to a variable &amp; 0 if its original. Eg..</p>
  
  <pre><code>    if (isset($tweet_object-&gt;retweeted_status)) {
    // This is a retweet
    // Use the original tweet's entities, they are more complete
    $entities = $tweet_object-&gt;retweeted_status-&gt;entities;
          $is_rt = 1; // Set 1 if retweeted
    } else {
        $entities = $tweet_object-&gt;entities;
        $is_rt = 0; // Set 0 if original
    }
  </code></pre>
  
  <p>Then just do like, </p>
  
  <pre><code>if($is_rt==0) // if its a original tweet
  {
    ...
    ....
  }
  </code></pre>