Twitter 搜索 API 允许开发者通过编程方式搜索和检索 Twitter 上的公开推文。确定对话(Conversation Thread)是指识别和获取与特定推文相关的完整对话链,包括原始推文及其所有回复。
原因:
解决方案:
import tweepy
# 初始化API客户端
client = tweepy.Client(bearer_token='YOUR_BEARER_TOKEN')
def get_conversation(conversation_id):
# 获取原始推文
original_tweet = client.get_tweet(conversation_id, tweet_fields=['conversation_id'])
# 搜索同一对话ID的所有推文
query = f"conversation_id:{original_tweet.data.conversation_id}"
tweets = client.search_recent_tweets(query=query, max_results=100)
return tweets.data
原因:
解决方案:
# 按时间排序对话
sorted_tweets = sorted(tweets.data, key=lambda x: x.created_at)
原因:
解决方案:
# 识别高互动回复
important_replies = [tweet for tweet in tweets.data
if tweet.public_metrics['reply_count'] > 5
or tweet.public_metrics['like_count'] > 10]
conversation_id
字段识别同一对话的推文in_reply_to_user_id
和referenced_tweets
字段构建对话树没有搜到相关的文章