gpt4 book ai didi

php - 在 Twitter Search API 1.1 中排除转推

转载 作者:IT王子 更新时间:2023-10-28 23:51:57 24 4
gpt4 key购买 nike

在这里,我尝试使用搜索 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: 请咨询医生#V57"

我用谷歌搜索并找到了这个 thread 。但它是旧的 API 版本。

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

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

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

search term 的末尾添加 -RT 将过滤它。

编辑:

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

永久的解决方案是,获取 RT 状态 & if 如果它的转推简单地为变量分配一个值,如 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 搜索运算符:

关于php - 在 Twitter Search API 1.1 中排除转推,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21748880/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com