在 Twitter 搜索 API 1.1 中排除转发

2024-01-31

在这里,我尝试使用搜索 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 https://stackoverflow.com/questions/7400656/twitter-search-atom-api-exclude-retweets。但它是旧的 API 版本。

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

这是在搜索 api 1.1 中排除转发的方法

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

在末尾添加-RTsearch term会过滤它。

EDIT :

如果他们的状态和用户名或屏幕名称中包含#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
{
  ...
  ....
}

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

如果你简单地添加-RT您可能会遇到意外过滤包含“RT”的推文的问题,例如“今日俄罗斯”将大量使用该字符串!

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

  • https://support.twitter.com/articles/71577-using-advanced-search https://support.twitter.com/articles/71577-using-advanced-search
  • http://thesocialchic.com/2013/04/26/how-to-master-twitter-search/ http://thesocialchic.com/2013/04/26/how-to-master-twitter-search/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在 Twitter 搜索 API 1.1 中排除转发 的相关文章

  • PHP strtotime() 未返回正确的月份

    由于当前月份 年份是 2012 年 1 月 为什么以下代码返回 2011 年 12 月而不是 2011 年 11 月 echo date F Y strtotime 2 months 如果有影响的话 这是在 PHP 5 3 0 上 要获得您
  • 间歇性 PHP 抽象类错误

    我已经为此奋斗了一段时间 但无法弄清楚 也许其他人也有 或者 Slim PHP Apache 等这里有更深层次的问题 在正常工作几个小时后 我的 Slim 安装将开始给出所有路线均如此 致命错误 类 Slim Collection 包含 1
  • NodeJS:将 JSON 保存到 MongoDB

    我正在尝试从 API 获取 JSON 并将其存储到 MongoDB 数据库中 显然 这是行不通的 我的应用程序似乎停留在我尝试将数据保存到数据库的位置 请告知该怎么做 这是我的代码 var express require express v
  • 是否可以在 PHP 中使用 file_get_contents 来破坏 CSRF 令牌验证

    在每个会话的表单上使用令牌的 CSRF 预防方法是一种流行的方法 但是 我不明白这种令牌方式如何保护file get contentsPHP 可以获取跨域文件表单的内容 gt 它可以获取表单上的令牌并使用它 那么这种token方式是如何运作
  • Doctrine 装置如何覆盖 purger 类?

    From doctrine fixture bundle the console doctrine fixtures load n命令定义如下 https github com doctrine DoctrineFixturesBundle
  • 无法加载文件或程序集“Newtonsoft.Json”或其依赖项之一

    首先 它不仅仅是重复的 以下问题的答案都不适合我 http goo gl tS40cn http goo gl tS40cn http goo gl pH6v2T http goo gl pH6v2T 我刚刚使用 Nuget 包管理器更新了
  • 如何轻松地将 Ajax、perl 和 JSON 结合使用?

    我正在尝试使用 Ajax 制作一个网页 Example 我创建了一个 Perl CGU 文件来触发一个简单的帖子 文件 test cgi name 托马斯 回复短信 你的名字是托马斯 我创建了一个可以使用该帖子的 html 文件 但随后页面
  • Laravel:使用 Faker 播种多个独特的列

    介绍 怎么样 伙计们 我有一个关于模型工厂和多个独特列的问题 背景 我有一个名为 Image 的模型 该模型将语言支持存储在单独的模型中 图片文字 图片文字 has an image id栏 语言栏和文本栏 图片文字有一个约束MySQL那个
  • 在 laravel 中禁用特定路由的 csrf

    我有一个支付系统 数据被提交到第三方网站然后被拉回 当数据返回时 它会到达特定的 url 比如 ok 路由 REQUEST transaction 但由于 Laravel 中间件 我遇到了令牌不匹配的情况 第三方支付API无法生成token
  • 使用 Mock 对 Laravel 5 Mail 进行单元测试

    有没有办法在 Laravel 5 中测试 Mail 尝试了我在互联网上看到的唯一合法的模拟示例 但它似乎只适用于 Laravel 4 下面的当前代码 mock Mockery mock Swift Mailer this gt app ma
  • 如何检查 $row['column_name'] 是否返回空 php mysql

    我有一个带有列的表格 id name phone describe 当我从这个表中获取值时 我正在使用 row mysql fetch array query 现在我想检查是否 row describe 返回空值 如何查看php 您可以使用
  • laravel 5.3 新的 Auth::routes()

    最近开始使用laravel 5 3写博客 但是运行后出现一个问题php artisan make auth 当我运行这个时 它会在我的web php 这是其中的代码 Auth routes Route get home HomeContro
  • 从 PHP 生成渐变颜色

    我想知道如何构建一个给出颜色代码和 显示该颜色的渐变 例如 function generate color int colorindex Generate 10 pale colors of this color 请帮我 迈克尔引用的代码相
  • css 字体 twitter 像关闭按钮一样,我错过了什么?

    twitter 有一个关闭按钮 它是单个字符 x 我需要类似的东西 但是在我检查之后 span x span 我按照 firebug 告诉我的那样创建 css 规则 close button font family Tahoma Arial
  • PHP MVC 应用程序中哪里可以捕获异常?

    我有一个中小型 PHP 应用程序 用于练习 OOP 和 MVC 技能 我有初始化 引导程序调用的文件Router谁打电话控制器 gt 服务层 gt 存储库 数据库 然后将变量发送回视图层 所有依赖项均由 DiC IOC 处理 我创建抽象类
  • Doctrine2:入门教程“没有要处理的元数据类”

    我已经将本教程的第一部分运行了三遍 到目前为止 在这里或其他地方进行的大量搜索都无法帮助我使其发挥作用 我收到 没有要处理的元数据类 当我尝试时 php vendor bin doctrine orm schema tool update
  • 如何通过 JsonConvert.DeserializeObject 在动态 JSON 中使用 null 条件运算符

    我正在使用 Newtonsoft 反序列化已知的 JSON 对象并从中检索一些值 如果存在 关键在于对象结构可能会不断变化 因此我使用动态来遍历结构并检索值 由于对象结构不断变化 我使用 null 条件运算符来遍历 JSON 代码看起来像这
  • 计算特定产品类别的购物车商品数量

    我试图仅从 WooCommerce 中的特定产品类别获取购物车中的商品数量 我正在为一家酒厂做一个网站 它有酒精和非酒精产品 所有葡萄酒都属于 葡萄酒 主类别或类别 ID 34 其下有许多子类别和产品 对于属于此类别的任何商品 我需要知道此
  • PHP:是否可以从文件内容(字符串)创建 SplFileObject 对象?

    例如 contents file get contents image png 是否可以从 contents 创建 SplFileObject 对象 Thanks php 有一些特殊的流包装器 http www php net manual
  • 合并 csv 文件 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 如何在 PHP 或 joomla 中将多个 CSV 文件合并为一个 csv 文件 将文件夹中 csv 文件中的所有数据合并到文本文件中 通

随机推荐