Tim*_*tle 47
据我所知,没有办法直接这样做(至少现在不行).似乎应该添加一些东西.他们最近添加了一些"转发"功能,这似乎也是合乎逻辑的.
这是一种可行的方法,首先是样本推文数据(来自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>
...
Run Code Online (Sandbox Code Playgroud)
从status/show你能找到用户的ID.然后statuses/mentions_timeline将返回用户的状态列表.只需解析返回,寻找in_reply_to_status_id与原始推文相匹配的内容id.
小智 42
以下是获取推文回复的程序
[q="to:$tweeterusername", sinceId = $tweetId]in_reply_to_status_id_str to $tweetid是帖子的回复.小智 19
Twitter API v2 现在使用conversation_id字段支持这一点。您可以在文档中阅读更多内容。
首先,请求conversation_id推文的字段。
https://api.twitter.com/2/tweets?ids=1225917697675886593&tweet.fields=conversation_id
Run Code Online (Sandbox Code Playgroud)
其次,然后使用conversation_id作为查询来搜索推文。
https://api.twitter.com/2/tweets/search/recent?query=conversation_id:1225912275971657728
Run Code Online (Sandbox Code Playgroud)
这是一个最小的示例,因此您应该根据需要向 URL 添加其他字段。
Twitter有一个名为related_results的无证api.它会为您提供指定推文ID的回复.不确定它的实验有多可靠,但这与在Twitter网站上调用的api调用相同.
使用风险由您自己承担.:)
https://api.twitter.com/1/related_results/show/172019363942117377.json?include_entities=1
Run Code Online (Sandbox Code Playgroud)
有关详细信息,请查看有关dev.twitter的讨论:https://dev.twitter.com/discussions/293
这是我的解决方案.它利用亚伯拉罕的Twitter Oauth PHP库:https://github.com/abraham/twitteroauth
它要求您了解Twitter用户的screen_name属性以及相关推文的id_str属性.这样,您就可以从任意用户的推文中获取任意对话Feed:
*更新:刷新代码以反映对象访问与阵列访问:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我分享简单的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.
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45732 次 |
| 最近记录: |