Здесь я пытаюсь получить твиты, которые имеют тег 'V57', используя поиск api 1.1. Сбрасывали и видели результаты поискового запроса, используя,
$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://img.ruphp.com/php/bg.gif" ["profile_background_image_url_https"]=> string(49) "http://img.ruphp.com/php/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://img.ruphp.com/php/bg.png" ["profile_background_image_url_https"]=> string(49) "http://img.ruphp.com/php/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)
в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://img.ruphp.com/php/bg.gif" ["profile_background_image_url_https"]=> string(49) "http://img.ruphp.com/php/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://img.ruphp.com/php/bg.png" ["profile_background_image_url_https"]=> string(49) "http://img.ruphp.com/php/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
, игнорируя все Retweets, подобные этому
string(131) "RT @useravv: Plz consult a doctor #V57"
Я googled и нашел эту нить . Но это была старая версия API.
Мое сомнение было очищено. Благодаря пользователю SO Newbi3 🙂
Вот способ исключить Retweets в Search api 1.1
$search_tim = $connection->get('search/tweets',array('q' => ' #V57 -RT', 'count' => 5,'result_type' => 'recent'));
Добавление -RT в конце search term
будет фильтровать его.
РЕДАКТИРОВАТЬ :
Вышеупомянутый подход просто устранит твитер, если они включили #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», например, «Russia Today» будет использовать эту строку довольно много!
На следующих страницах описаны операторы поиска в Twitter: