我正在处理一个项目,需要检索Twitter用户的对话。例如,我想获取BBC World Service这条推文的所有回复。使用REST API v1.1,我可以获取Twitter用户的时间轴(推文,转推)。但是,我没有找到任何有关获取特定推文回复的文档/解决方法。是否有任何方法来获取特定推文的回复?
没有用于获取特定推文回复的API调用。 不过,您可以作弊!
使用搜索API,您可以构建一个搜索查询,其中:
@bbcworldservice
的。因此,在这种情况下,可以使用以下内容进行搜索:
https://api.twitter.com/1.1/search/tweets.json?
q=%23bbcworldservice&
since_id=489366839953489920&
count=100
您将获得一份推文列表(最多100个)。然后,您需要搜索它们以查找in_reply_to_status_id_str
,并查看它是否与您正在寻找的状态匹配。
curl --request GET \
--url 'https://api.twitter.com/2/tweets?ids=1225917697675886593&tweet.fields=author_id,conversation_id,created_at,in_reply_to_user_id,referenced_tweets&expansions=author_id,in_reply_to_user_id,referenced_tweets.id&user.fields=name,username' \
--header 'Authorization: Bearer $BEARER_TOKEN'
{
"data": [
{
"id": "1225917697675886593",
"text": "@TwitterEng",
"created_at": "2020-02-07T23:02:10.000Z",
"author_id": "2244994945",
"in_reply_to_user_id": "6844292",
"conversation_id": "1225912275971657728",
"referenced_tweets": [
{
"type": "quoted",
"id": "1200517737669378053"
},
{
"type": "replied_to",
"id": "1225912275971657728"
}
]
}
],
"includes": {
"users": [
{
"username": "TwitterDev",
"name": "Twitter Dev",
"id": "2244994945"
},
{
"username": "TwitterEng",
"name": "Twitter Engineering",
"id": "6844292"
}
],
"tweets": [
{
"id": "1200517737669378053",
"text": "| ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄ ̄|\n don't push \n to prod on \n Fridays \n|___________| \n(\\__/) ||\n(•ㅅ•) ||\n/ づ",
"created_at": "2019-11-29T20:51:47.000Z",
"author_id": "2244994945",
"conversation_id": "1200517737669378053"
},
{
"id": "1225912275971657728",
"text": "Note to self: Don't deploy on Fridays",
"created_at": "2020-02-07T22:40:37.000Z",
"author_id": "6844292",
"conversation_id": "1225912275971657728"
}
]
}
}
更多信息请查看 Twitter API 的Conversation页面。