用户推文
获取Twitter用户推文列表的API
用户推文
获取指定Twitter用户的推文列表。
请求
URL: /api/twitter/user-tweets
方法: GET 或 POST
请求参数:
| 参数名 | 类型 | 必需 | 描述 |
|---|---|---|---|
| restId | string | 是 | 用户的唯一ID标识符 |
| cursor | string | 否 | 分页游标,用于获取下一页数据 |
响应
成功响应会返回包含用户推文的列表,以时间倒序排列,包括推文内容、创建时间、点赞数、转发数等详细信息。
示例
请求示例
# GET 请求
curl --request GET \
--url 'https://www.aidir.fun/api/twitter/user-tweets?restId=44196397' \
--header 'X-API-Key: <api-key>'
# POST 请求
curl --request POST \
--url 'https://www.aidir.fun/api/twitter/user-tweets' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: <api-key>' \
--data '{
"restId": "44196397"
}'响应示例
{
"data": {
"user": {
"result": {
"id": "44196397",
"rest_id": "44196397",
"name": "Elon Musk",
"screen_name": "elonmusk"
}
},
"timeline": {
"instructions": [
{
"entries": [
{
"content": {
"tweet": {
"id": "1512345678901234567",
"text": "This is a tweet example",
"created_at": "2023-04-15T14:34:12.000Z",
"favorite_count": 12345,
"retweet_count": 6789,
"reply_count": 1234,
"quote_count": 567,
"has_media": true,
"media": [
{
"type": "photo",
"url": "https://pbs.twimg.com/media/sample.jpg"
}
]
}
}
}
]
}
]
}
}
}错误响应
| 状态码 | 描述 |
|---|---|
| 400 | 请求参数错误,例如缺少必需的 restId 参数 |
| 401 | 认证失败,API密钥无效或缺失 |
| 404 | 用户不存在或没有推文 |
| 500 | 服务器内部错误 |
获取用户restId
要使用此API,您需要知道用户的restId。您可以通过以下方法获取:
- 使用用户资料API查询用户的基本信息,其中包含restId
- 在Twitter网页版上,用户的个人资料URL通常包含其数字ID,如
https://twitter.com/i/user/44196397
分页说明
在第一次请求的响应中(例如:https://www.aidir.fun/api/twitter/user-tweets?restId=44196397),您可以在数据的最末尾找到 cursor-bottom- 的条目:
{
"entryId": "cursor-bottom-2000585960391180262",
"sortIndex": "2000585960391180262",
"content": {
"entryType": "TimelineTimelineCursor",
"__typename": "TimelineTimelineCursor",
"value": "DAAHCgABG8OCVNe__-YLAAIAAAATMjAwMDQ0ODY2ODcwMTQzMDEwNggAAwAAAAIAAA",
"cursorType": "Bottom"
}
}获取 content.value 的值(即 cursor),并将其作为 cursor 参数添加到请求 URL 中以获取下一页数据:
https://www.aidir.fun/api/twitter/user-tweets?restId=44196397&cursor=DAAHCgABG8OCVNe__-YLAAIAAAATMjAwMDQ0ODY2ODcwMTQzMDEwNggAAwAAAAIAAA
AIDIR文档