LogoAIDIR文档

推文搜索

搜索Twitter推文的API

推文搜索

搜索Twitter上的推文,通过关键词查找相关内容。

请求

URL: /api/twitter/search

方法: GETPOST

请求参数:

参数名类型必需描述
rawQuerystring搜索查询字符串,可以包含关键词、用户名、标签等

响应

成功响应会返回匹配搜索查询的推文列表,按相关性排序,包括推文内容、创建时间、作者信息等。

示例

请求示例

# GET 请求
curl --request GET \
  --url 'https://www.aidir.fun/api/twitter/search?rawQuery=artificial%20intelligence' \
  --header 'X-API-Key: <api-key>'
 
# POST 请求
curl --request POST \
  --url 'https://www.aidir.fun/api/twitter/search' \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '{
    "rawQuery": "artificial intelligence"
  }'

响应示例

{
  "data": {
    "search_metadata": {
      "query": "artificial intelligence",
      "count": 10
    },
    "timeline": {
      "instructions": [
        {
          "entries": [
            {
              "content": {
                "tweet": {
                  "id": "1512345678901234567",
                  "text": "The latest developments in artificial intelligence are truly amazing!",
                  "created_at": "2023-04-15T14:34:12.000Z",
                  "author": {
                    "id": "9876543210",
                    "name": "Tech Enthusiast",
                    "screen_name": "techenthusiast"
                  },
                  "favorite_count": 123,
                  "retweet_count": 45,
                  "reply_count": 6,
                  "quote_count": 2
                }
              }
            }
          ]
        }
      ]
    }
  }
}

错误响应

状态码描述
400请求参数错误,例如缺少必需的 rawQuery 参数
401认证失败,API密钥无效或缺失
500服务器内部错误

搜索技巧

可以在搜索查询中使用以下语法来优化搜索结果:

  • from:username - 查找特定用户发布的推文
  • #hashtag - 查找包含特定标签的推文
  • "exact phrase" - 查找包含精确短语的推文
  • since:YYYY-MM-DD - 查找特定日期之后的推文
  • until:YYYY-MM-DD - 查找特定日期之前的推文

例如,搜索查询 "artificial intelligence" from:elonmusk since:2023-01-01 将查找Elon Musk在2023年1月1日之后发布的包含"artificial intelligence"精确短语的推文。

目录