在Twitter搜索API 1.1中排除转推

21

我正在尝试使用搜索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"

我已经搜索并找到了这个帖子。但它是旧的API版本。

我的疑问得到了解答。感谢SO用户Newbi3 :)

这里是在Search api 1.1中排除转推的方法

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

在搜索词的末尾添加-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
{
  ...
  ....
}

这可能会暂时有所帮助。我还没有测试过它。https://dev.twitter.com/discussions/20652似乎也有人请求这个功能。https://dev.twitter.com/discussions/22457 - Newbi3
嗨@Newbi3,我正在使用Abraham库,这是我的查询以搜索特定标签的推文$search_tim = $connection->get('search/tweets',array('q' => ' #Vijay57', 'count' => 5, 'result_type' => 'recent'));。Twitter Doc中没有给出包含此类参数的说明。如果能简要说明一下会很有帮助。我是新手! - user3289108
1
根据开发人员的讲话,它说:“尝试将“-RT”添加到搜索查询中。”意思是在您的q变量末尾添加“-RT”。空格很重要。 - Newbi3
我会逐个尝试额外的参数。例如,我会先使用一些值(如您刚获取的推文的ID)测试since_id。如果同时使用since_idmax_id可能会得到0个结果。基本上,独立测试它们,然后再将它们组合起来。将问题分解成较小的部分。一旦您有了可行的代码,那么再进行优化! - Newbi3
https://dev.twitter.com/issues/1208。你可能已经发现了他们API中的一个错误,我不确定,因为我没有在积极开发这个API。但是,我认为使用recent和计数X或5将为您提供最新和更可预测的结果。 - Newbi3
显示剩余4条评论
1个回答

42

5
刚刚确认“-filter:retweets”对我起作用了。谢谢! - kyle

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接