在Twitter Search API 1.1中排除转推

时间:2014-02-13 08:34:20

标签: php json twitter

这里我正在尝试使用search api 1.1检索包含标签'V57'的推文。倾倒&通过使用

看到了搜索词的结果

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

执行 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)

现在,我想通过忽略所有类似于此的转推

来单独检索具有V57标记的原始推文

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

我用谷歌搜索了thread。但它是旧的API版本。

我的疑虑已被清除。感谢SO用户Newbi3 :)

以下是在搜索API 1.1中排除转推的方法

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

search term末尾添加-RT将对其进行过滤。

编辑:

如果#RT包含在他们的状态和用户名或屏幕名称中,上述方法也会简单地删除推文。当它看到RT时,这将盲目地忽略推文。这是一个临时解决方案。

永久解决方案是,获得RT状态&如果它的转发只是简单地将一个值1赋给变量& 0如果是原始的。例如..

    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
  }

然后就是这样,

if($is_rt==0) // if its a original tweet
{
  ...
  ....
}

1 个答案:

答案 0 :(得分:41)

我发现将"-filter:retweets"连接到查询字符串的末尾效果最好。

如果您只是添加-RT,则可能会遇到意外过滤包含" RT"例如"今日俄罗斯"将使用该字符串非常多!

以下页面描述了Twitter搜索运算符: