API Hop

文件目錄

API Hop 文件

查詢使用者時間軸

依使用者 ID 查詢 Twitter 使用者時間軸,並傳回正規化推文、作者展開資料及分頁中繼資料。

GEThttps://api.apihop.ai/v1/twitter/users/{id}/tweets

依正規化的使用者 ID 查詢時間軸。此端點傳回 X API v2 風格的 data / includes / meta 結構。

text
GET https://api.apihop.ai/v1/twitter/users/{id}/tweets

驗證

所有 Twitter API 端點均需要 Bearer Token 驗證。

http
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 中的欄位。

請求範例

bash
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_atstring

ISO 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必填

目前頁面的推文數量。

成功範例

json
{
  "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
  }
}

錯誤回應

完整代碼參考、協定差異及診斷步驟,請見錯誤代碼與疑難排解。

json
{
  "success": false,
  "error": {
    "code": 40000,
    "message": "Insufficient credit. Required: 100000, Available: 99999"
  },
  "requestId": "req_xxx"
}

分頁

若有 meta.next_token,請將其作為 pagination_token 傳入,以取得下一頁。