API Hop 文件
依使用者名稱查詢使用者
依使用者名稱查詢 Twitter 個人資料,並傳回正規化的 X API v2 風格使用者物件。
GET
https://api.apihop.ai/v1/twitter/users使用 username 查詢使用者個人資料。當您只知道使用者名稱,需要取得正規化的 data.id 來查詢時間軸時,此端點很有用。
text
GET https://api.apihop.ai/v1/twitter/users驗證
所有 Twitter API 端點均需要 Bearer Token 驗證。
http
Authorization: Bearer YOUR_API_KEY查詢參數
usernamestring必填Twitter 使用者名稱。接受 elonmusk 與 @elonmusk;伺服器端會移除開頭的 @。
user.fieldsstring以逗號分隔的使用者欄位,例如 created_at,description,public_metrics,verified。
請求範例
bash
curl --request GET \
"$API_BASE_URL/v1/twitter/users?username=elonmusk&user.fields=created_at,description,public_metrics,verified" \
--header "Authorization: Bearer YOUR_API_KEY"回應
dataobject必填正規化的使用者物件。
data 欄位
idstring必填使用者的唯一識別碼。查詢時間軸時建議優先使用此值。
namestring必填顯示名稱。
usernamestring必填不含 @ 的使用者名稱。
created_atstringISO 8601 時間戳記,在請求 user.fields=created_at 時傳回。
descriptionstring使用者簡介。
entitiesobject個人資料實體,例如網址說明與連結。
locationstring使用者個人資料中的所在地。
pinned_tweet_idstring置頂推文的 ID。
profile_banner_urlstring個人資料橫幅網址。
profile_image_urlstring個人資料圖片網址。
protectedboolean帳號是否受到保護。
public_metricsobject公開使用者指標。
public_metrics 欄位
followers_countinteger追蹤者人數。
following_countinteger追蹤的帳號數量。
tweet_countinteger推文總數。
listed_countinteger包含此使用者的列表數量。資料來源未提供時可能缺少此欄位。
urlstring使用者個人資料中的網站網址。
verifiedboolean帳號是否已驗證。
verified_typestring驗證類型,例如 Business。
成功範例
json
{
"data": {
"id": "44196397",
"name": "Elon Musk",
"username": "elonmusk",
"created_at": "2009-06-02T20:12:29.000Z",
"description": "Mars and cars",
"public_metrics": {
"followers_count": 10,
"following_count": 20,
"tweet_count": 40
},
"verified": true
}
}錯誤回應
完整代碼參考、協定差異及診斷步驟,請見錯誤代碼與疑難排解。
json
{
"success": false,
"error": {
"code": 40000,
"message": "Insufficient credit. Required: 100000, Available: 99999"
},
"requestId": "req_xxx"
}使用提示
- 若只知道
username,請先呼叫此端點 - 若要查詢時間軸,請使用傳回的
data.id - 若只需要頭像、簡介或追蹤者人數,請明確傳入
user.fields