API Hop 文件
查詢使用者時間軸
依使用者 ID 查詢 Twitter 使用者時間軸,並傳回正規化推文、作者展開資料及分頁中繼資料。
https://api.apihop.ai/v1/twitter/users/{id}/tweets依正規化的使用者 ID 查詢時間軸。此端點傳回 X API v2 風格的 data / includes / meta 結構。
GET https://api.apihop.ai/v1/twitter/users/{id}/tweets驗證
所有 Twitter API 端點均需要 Bearer Token 驗證。
Authorization: Bearer YOUR_API_KEY路徑參數
idstring必填Twitter 使用者 ID,例如 44196397。
查詢參數
max_resultsinteger預設: 10每頁傳回的推文數量,範圍為 1 至 100。
pagination_tokenstring下一頁的游標,從上一個回應的 meta.next_token 複製。
excludestring以逗號分隔的排除規則。支援的值包含 replies 與 retweets。
expansionsstring以逗號分隔的展開欄位。使用 author_id 以包含 includes.users。
tweet.fieldsstring以逗號分隔的推文欄位,例如 created_at,public_metrics,attachments,source。
user.fieldsstring請求 expansions=author_id 時,控制 includes.users 中的欄位。
請求範例
curl --request GET \
"$API_BASE_URL/v1/twitter/users/44196397/tweets?max_results=5&exclude=retweets,replies&expansions=author_id&tweet.fields=created_at,public_metrics,attachments,author_id,conversation_id&user.fields=public_metrics" \
--header "Authorization: Bearer YOUR_API_KEY"回應
dataobject[]必填時間軸推文列表。
推文欄位
idstring必填推文 ID。
textstring必填推文文字內容。
attachmentsobject媒體參照,目前以 media_keys 傳回。
author_idstring作者 ID。請求 expansions=author_id 時,對應至 includes.users。
conversation_idstring對話 ID。
created_atstringISO 8601 格式的推文建立時間。
edit_history_tweet_idsstring[]編輯歷程中的推文 ID。
entitiesobject解析後的推文實體,例如主題標籤、網址及提及。
in_reply_to_user_idstring被回覆使用者的 ID。
langstring推文語言。
possibly_sensitiveboolean內容是否敏感。
public_metricsobject公開推文指標。
public_metrics 欄位
retweet_countinteger轉推次數。
reply_countinteger回覆次數。
like_countinteger按讚次數。
quote_countinteger引用次數。
bookmark_countinteger加入書籤次數。
impression_countinteger曝光次數。
referenced_tweetsobject[]參照的推文。type 可以是 retweeted、quoted 或 replied_to。
sourcestring推文來源,例如客戶端或網頁。
includesobject展開的物件。當 expansions 包含 author_id 時出現。
includes 欄位
usersobject[]與 author_id 對應的作者列表。
metaobject必填分頁與結果中繼資料。
meta 欄位
newest_idstring目前頁面最新的推文 ID。
oldest_idstring目前頁面最舊的推文 ID。
next_tokenstring下一頁的游標。請以 pagination_token 傳送。
result_countinteger必填目前頁面的推文數量。
成功範例
{
"data": [
{
"id": "tweet-1",
"text": "Hello Mars",
"author_id": "44196397",
"created_at": "2025-04-22T10:00:00.000Z",
"public_metrics": {
"retweet_count": 3,
"reply_count": 2,
"like_count": 7
}
}
],
"includes": {
"users": [
{
"id": "44196397",
"name": "Elon Musk",
"username": "elonmusk"
}
]
},
"meta": {
"newest_id": "tweet-1",
"oldest_id": "tweet-1",
"next_token": "cursor-123",
"result_count": 1
}
}錯誤回應
完整代碼參考、協定差異及診斷步驟,請見錯誤代碼與疑難排解。
{
"success": false,
"error": {
"code": 40000,
"message": "Insufficient credit. Required: 100000, Available: 99999"
},
"requestId": "req_xxx"
}分頁
若有 meta.next_token,請將其作為 pagination_token 傳入,以取得下一頁。