获取私信聊天历史 (XChat v3)
基于 XChat v3 协议高速拉取指定私信会话的历史聊天记录。需附带 Twitter Cookie。
返回 API 接口列表
/DM Endpoints
POST
/v3/twitter/dm-historyAPI 鉴权
AuthorizationBearer token · header必填TwexAPI 平台的全局身份凭据 (Bearer Token)。所有接口调用均需在 Header 中携带:Authorization: Bearer <YOUR_TWEXAPI_KEY>。可在 TwexAPI 用户控制台获取。
请求体
必填application/jsonrecipientstring必填私信会话对象(可填写数字用户 ID、@用户名、会话 ID a:b、或群聊 ID g...)
pinstring | any安全身份识别 PIN 码(默认 1234)。
default: "1234"
展开属性折叠属性
Any of:
string
stringany
anycountinteger | any要获取的记录数量上限
default: 50
展开属性折叠属性
Any of:
integer
integerany
anyallboolean | any是否自动遍历全部游标以拉取所有页面数据
default: false
展开属性折叠属性
Any of:
boolean
booleanany
anybeforestring | any分页用的最旧消息 sequenceId。传入上一页中最旧消息的 sequence_id 进行向上翻页。
展开属性折叠属性
Any of:
string
stringany
anycookiestring必填用户自有授权的 Twitter 会话凭据或 auth_token(BYOC 自带 Cookie 模式)。无状态受托代理执行,凭据绝不持久化存储。详见 [鉴权与安全说明](/zh/authentication#写操作鉴权与-byoc自带授权-cookie--token) 与 [获取 Cookie 指南](https://youtube-promotion.pages.dev/how-to-get-twitter-cookie)。
proxystring | any可选配置的 HTTP 代理地址,格式示例:http://username:password@ip:port
展开属性折叠属性
Any of:
string
stringany
any响应结果
200带有分页信息的私信会话消息列表。
codeinteger必填HTTP 响应状态码(200 表示成功)
msgstring必填响应提示信息(例如 'success')
dataDmHistoryV3Data | any接口返回的核心业务数据载荷
展开属性折叠属性
Any of:
DmHistoryV3Data
conversation_idstring必填私信会话窗口唯一标识符
has_moreboolean必填是否仍有更早的历史消息记录可供继续拉取
messagesMessageModel[]必填私信消息对象列表
展开属性折叠属性
Array of
MessageModelidstring必填私信消息唯一 ID
textstring必填文本正文内容
timestring必填私信发送时间(时间戳)
attachmentobject | any私信媒体附件信息
展开属性折叠属性
Any of:
object
objectany
anyattachmentsobject[] | any私信随信附带的媒体文件列表
展开属性折叠属性
Any of:
object[]
Array of
objectobjectany
anysequence_idstring | anyXChat 消息唯一连续序列号 sequence_id。分页向上翻页时将最旧一条消息的 sequence_id 作为 before 参数传入。
展开属性折叠属性
Any of:
string
stringany
anysender_idstring | any私信发送者的推特用户数字 ID
展开属性折叠属性
Any of:
string
stringany
anyrecipient_idstring | any私信接收者的推特用户数字 ID
展开属性折叠属性
Any of:
string
stringany
anyany
any422请求参数校验错误
detailValidationError[]展开属性折叠属性
Array of
ValidationErrorlocstring | integer[]必填展开属性折叠属性
Array of
string | integerAny of:
string
stringinteger
integermsgstring必填响应提示信息(例如 'success')
typestring必填inputanyctxobject⚡交互式测试POST
⚡交互式测试 / Try APIPOSTLive Console
🌐目标服务器:
https://api.twexapi.io● 生产环境就绪
✍️
写入接口凭证指引(TwexAPI 密钥 + 目标推特 Cookie)
1. TwexAPI 平台密钥 (Bearer Token):在下方「API 鉴权」中填入,用于 TwexAPI 计费与接口调用鉴权。
2. 推特账号 Cookie:本接口为代发/点赞/关注等写操作,需在下方请求体 (Request Body) 的 cookie 字段中填入目标 Twitter 账号的 Cookie 凭据(如 auth_token=...; ct0=...)。
🔑API 鉴权
📝请求体application/json
📡
暂无响应数据
请在「请求配置」中确认参数后,点击底部的「发送请求」按钮。
请求示例
curl -X POST "https://api.twexapi.io/v3/twitter/dm-history" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"recipient": "1928096185664843776:1989842918455291904",
"pin": "1234",
"count": 50,
"all": false,
"before": "2076684837654876160",
"cookie": "ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7",
"proxy": "http://username:password@ip:port"
}'const response = await fetch("https://api.twexapi.io/v3/twitter/dm-history", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
body: JSON.stringify({
"recipient": "1928096185664843776:1989842918455291904",
"pin": "1234",
"count": 50,
"all": false,
"before": "2076684837654876160",
"cookie": "ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7",
"proxy": "http://username:password@ip:port"
})
});import requests
response = requests.post(
"https://api.twexapi.io/v3/twitter/dm-history",
headers={
"Authorization": "Bearer YOUR_TOKEN",
"Content-Type": "application/json"
},
json={
"recipient": "1928096185664843776:1989842918455291904",
"pin": "1234",
"count": 50,
"all": False,
"before": "2076684837654876160",
"cookie": "ct0=abc123... or 2c4a4e1832096aa694c739b83c83b6d96d43eba7",
"proxy": "http://username:password@ip:port"
},
)响应示例
{
"code": 200,
"msg": "success",
"data": {
"conversation_id": "1928096185664843776:1989842918455291904",
"has_more": true,
"messages": [
{
"id": "1234567890123456789",
"text": "Hello, how are you?",
"time": "2024-01-01T12:00:00Z",
"attachment": {
"type": "image",
"url": "https://example.com/image.jpg"
},
"attachments": [
{
"attachment_id": "cda5ccdd-af53-48a3-bdd1-5039a73aea25",
"conversation_id": "1928096185664843776:1989842918455291904",
"filename": "image.jpg",
"filesize_bytes": 421299,
"height": 1448,
"key_version": "3",
"media_hash_key": "blRIlZCVIO",
"type": "image",
"type_name": "IMAGE",
"width": 1086
}
],
"sequence_id": "2076661179334979585",
"sender_id": "1234567890123456789",
"recipient_id": "1234567890123456789"
}
]
}
}{
"detail": [
{
"loc": [
"string"
],
"msg": "string",
"type": "string",
"input": null,
"ctx": {}
}
]
}