回复特定的推特,Twitter的API

Twitter API中有没有一种方法可以获得对特定推文的回复? 谢谢

据我所知,没有办法直接做(至less不是现在)。 似乎应该加上一些东西。 他们最近添加了一些“转推”function,似乎合乎逻辑地增加了这一点。

这里有一个可能的方法来做到这一点,首先示例鸣叫数据(从status/show ):

 <status> <created_at>Tue Apr 07 22:52:51 +0000 2009</created_at> <id>1472669360</id> <text>At least I can get your humor through tweets. RT @abdur: I don't mean this in a bad way, but genetically speaking your a cul-de-sac.</text> <source><a href="http://www.tweetdeck.com/">TweetDeck</a></source> <truncated>false</truncated> <in_reply_to_status_id></in_reply_to_status_id> <in_reply_to_user_id></in_reply_to_user_id> <favorited>false</favorited> <in_reply_to_screen_name></in_reply_to_screen_name> <user> <id>1401881</id> ... 

status/show你可以find用户的ID。 然后, statuses/mentions_timeline将返回用户的状态列表。 只是parsing返回寻找一个匹配原来的推特idin_reply_to_status_id

以下是获取推文回复的程序

  1. 当你获取tweetId,即。,id_str
  2. 使用twittersearchapi做以下查询[q="to:$tweeterusername", sinceId = $tweetId]
  3. 循环所有的结果,匹配in_reply_to_status_id_str to $tweetid的结果是post的回复。

Twitter有一个名为related_results的未公开的API。 它会给你指定的鸣叫ID的答复。 不知道它是如何可靠的实验,但这是相同的API调用是在Twitter的networking上。

使用风险自负。 🙂

 https://api.twitter.com/1/related_results/show/172019363942117377.json?include_entities=1 

欲了解更多信息,请参阅关于dev.twitter的讨论: https ://dev.twitter.com/discussions/293

这是我的解决scheme。 它利用亚伯拉罕的Twitter Oauth PHP库: https : //github.com/abraham/twitteroauth

它要求您了解Twitter用户的screen_name属性以及相关tweet的id_str属性。 这样,您可以从任意用户的推文中获得任意的对话提要:

*更新:刷新的代码,以反映对象访问VS数组访问:

 function get_conversation($id_str, $screen_name, $return_type = 'json', $count = 100, $result_type = 'mixed', $include_entities = true) { $params = array( 'q' => 'to:' . $screen_name, // no need to urlencode this! 'count' => $count, 'result_type' => $result_type, 'include_entities' => $include_entities, 'since_id' => $id_str ); $feed = $connection->get('search/tweets', $params); $comments = array(); for ($index = 0; $index < count($feed->statuses); $index++) { if ($feed->statuses[$index]->in_reply_to_status_id_str == $id_str) { array_push($comments, $feed->statuses[$index]); } } switch ($return_type) { case 'array': return $comments; break; case 'json': default: return json_encode($comments); break; } } 

不是一个简单实用的方式。 有一个function要求:

http://code.google.com/p/twitter-api/issues/detail?id=142

有几个提供API的第三方网站,但他们经常错过状态。

我已经通过以下方式实现了这一点:

1)状态/更新返回最后一个状态的ID(如果include_entities为true)2)然后你可以请求状态/提及,并通过in_reply_to_status_id过滤结果。 后者应该与步骤1中的特定ID相同

在这里,我分享简单的R代码来获取特定鸣叫的回复

 userName = "SrBachchan" ##fetch tweets from @userName timeline tweets = userTimeline(userName,n = 1) ## converting tweets list to DataFrame tweets <- twListToDF(tweets) ## building queryString to fetch retweets queryString = paste0("to:",userName) ## retrieving tweet ID for which reply is to be fetched Id = tweets[1,"id"] ## fetching all the reply to userName rply = searchTwitter(queryString, sinceID = Id) rply = twListToDF(rply) ## eliminate all the reply other then reply to required tweet Id rply = rply[!rply$replyToSID > Id,] rply = rply[!rply$replyToSID < Id,] rply = rply[complete.cases(rply[,"replyToSID"]),] ## now rply DataFrame contains all the required replies. 

几个月前我在工作中遇到过同样的问题,因为我之前在REST V1中使用其related_tweets端点。

所以我不得不build立一个解决方法,我已经在这里logging。 http://adriancrepaz.com/twitter_conversations_api

这个class应该做你想要的。 它刮擦移动网站的HTML,并parsing对话。 我用了一段时间,似乎很可靠。

要取得交谈…

请求

 <?php require_once 'acTwitterConversation.php'; $twitter = new acTwitterConversation; $conversation = $twitter->fetchConversion(324215761998594048); print_r($conversation); ?> 

响应

 Array ( [error] => false [tweets] => Array ( [0] => Array ( [id] => 324214451756728320 [state] => before [username] => facebook [name] => Facebook [content] => Facebook for iOS v6.0 ? Now with chat heads and stickers in private messages, and a more beautiful News Feed on iPad itunes.apple.com/us/app/faceboo? [date] => 16 Apr [images] => Array ( [thumbnail] => https://pbs.twimg.com/profile_images/3513354941/24aaffa670e634a7da9a087bfa83abe6_normal.png [large] => https://pbs.twimg.com/profile_images/3513354941/24aaffa670e634a7da9a087bfa83abe6.png ) ) [1] => Array ( [id] => 324214861728989184 [state] => before [username] => michaelschultz [name] => Michael Schultz [content] => @facebook good April Fools joke Facebook?.chat hasn?t changed. No new features. [date] => 16 Apr [images] => Array ( [thumbnail] => https://pbs.twimg.com/profile_images/414193649073668096/dbIUerA8_normal.jpeg [large] => https://pbs.twimg.com/profile_images/414193649073668096/dbIUerA8.jpeg ) ) .... ) ) 

希望它有帮助,阿德里安。

作为国家satheesh它很好。 这里是我使用的REST API代码

 ini_set('display_errors', 1); require_once('TwitterAPIExchange.php'); /** Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "xxxx", 'oauth_access_token_secret' => "xxxx", 'consumer_key' => "xxxx", 'consumer_secret' => "xxxx" ); // Your specific requirements $url = 'https://api.twitter.com/1.1/search/tweets.json'; $requestMethod = 'GET'; $getfield = '?q=to:screen_name&sinceId=twitter_id'; // Perform the request $twitter = new TwitterAPIExchange($settings); $b = $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(); $arr = json_decode($b,TRUE); echo "Replies <pre>"; print_r($arr); die;