curl \
-H "Authorization: Bearer API_KEY" \
-H "x-twitter-oauth1-api-key: YOUR_TWITTER_API_KEY" \
-H "x-twitter-oauth1-api-secret: YOUR_TWITTER_API_SECRET" \
-X GET "https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15"
const API_KEY = "API_KEY";
fetch(
"https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15",
{
method: "GET",
headers: {
Authorization: `Bearer ${API_KEY}`,
"x-twitter-oauth1-api-key": "YOUR_TWITTER_API_KEY",
"x-twitter-oauth1-api-secret": "YOUR_TWITTER_API_SECRET"
}
}
)
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
'Authorization': 'Bearer API_KEY',
'x-twitter-oauth1-api-key': 'YOUR_TWITTER_API_KEY',
'x-twitter-oauth1-api-secret': 'YOUR_TWITTER_API_SECRET'
}
params = {
'query': 'ayrshare OR #socialmedia',
'platform': 'twitter',
'limit': 15
}
r = requests.get('https://api.ayrshare.com/api/listen/keyword', headers=headers, params=params)
print(r.json())
{
"status": "success",
"platform": "twitter",
"query": "ayrshare OR #socialmedia",
"tweets": [
{
"id": "1234567890",
"text": "Just discovered @ayrshare for managing social media APIs!",
"createdAt": "2026-03-22T14:30:00.000Z",
"user": {
"id": "987654321",
"name": "Jane Doe",
"screenName": "janedoe",
"profileImageUrl": "https://pbs.twimg.com/profile_images/..."
},
"metrics": {
"retweetCount": 5,
"favoriteCount": 12
},
"entities": {
"hashtags": ["socialmedia"],
"mentions": ["ayrshare"],
"urls": []
},
"inReplyToStatusId": null,
"isRetweet": false,
"lang": "en"
}
],
"meta": {
"pagination": {
"hasMore": true,
"next": "b26v89c19zqg8o3fpds7h...",
"limit": 15
}
}
}
{
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs.",
"details": "The 'query' parameter is required."
}
{
"status": "error",
"code": 401,
"message": "Unauthorized. BYOK keys for X/Twitter are required.",
"details": "Please set up your X/Twitter API keys. See https://docs.ayrshare.com/dashboard/connect-social-accounts/x-twitter-byo-keys"
}
{
"status": "error",
"code": 429,
"message": "Rate limit exceeded. Daily limit of 25 keyword search calls reached.",
"details": "Please try again tomorrow or contact support for higher limits."
}
Keyword
Tìm kiếm Tweets theo Từ khóa
Tìm kiếm X/Twitter cho các tweets khớp với từ khóa hoặc hashtag
GET
/
listen
/
keyword
curl \
-H "Authorization: Bearer API_KEY" \
-H "x-twitter-oauth1-api-key: YOUR_TWITTER_API_KEY" \
-H "x-twitter-oauth1-api-secret: YOUR_TWITTER_API_SECRET" \
-X GET "https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15"
const API_KEY = "API_KEY";
fetch(
"https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15",
{
method: "GET",
headers: {
Authorization: `Bearer ${API_KEY}`,
"x-twitter-oauth1-api-key": "YOUR_TWITTER_API_KEY",
"x-twitter-oauth1-api-secret": "YOUR_TWITTER_API_SECRET"
}
}
)
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
'Authorization': 'Bearer API_KEY',
'x-twitter-oauth1-api-key': 'YOUR_TWITTER_API_KEY',
'x-twitter-oauth1-api-secret': 'YOUR_TWITTER_API_SECRET'
}
params = {
'query': 'ayrshare OR #socialmedia',
'platform': 'twitter',
'limit': 15
}
r = requests.get('https://api.ayrshare.com/api/listen/keyword', headers=headers, params=params)
print(r.json())
{
"status": "success",
"platform": "twitter",
"query": "ayrshare OR #socialmedia",
"tweets": [
{
"id": "1234567890",
"text": "Just discovered @ayrshare for managing social media APIs!",
"createdAt": "2026-03-22T14:30:00.000Z",
"user": {
"id": "987654321",
"name": "Jane Doe",
"screenName": "janedoe",
"profileImageUrl": "https://pbs.twimg.com/profile_images/..."
},
"metrics": {
"retweetCount": 5,
"favoriteCount": 12
},
"entities": {
"hashtags": ["socialmedia"],
"mentions": ["ayrshare"],
"urls": []
},
"inReplyToStatusId": null,
"isRetweet": false,
"lang": "en"
}
],
"meta": {
"pagination": {
"hasMore": true,
"next": "b26v89c19zqg8o3fpds7h...",
"limit": 15
}
}
}
{
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs.",
"details": "The 'query' parameter is required."
}
{
"status": "error",
"code": 401,
"message": "Unauthorized. BYOK keys for X/Twitter are required.",
"details": "Please set up your X/Twitter API keys. See https://docs.ayrshare.com/dashboard/connect-social-accounts/x-twitter-byo-keys"
}
{
"status": "error",
"code": 429,
"message": "Rate limit exceeded. Daily limit of 25 keyword search calls reached.",
"details": "Please try again tomorrow or contact support for higher limits."
}
Tìm kiếm X/Twitter để tìm các tweets khớp với từ khóa, hashtag và các toán tử tìm kiếm nâng cao. Trả về dữ liệu tweet đã được chuẩn hóa bao gồm thông tin người dùng, số liệu tương tác và các thực thể.
Endpoint này yêu cầu Bring Your Own Keys (BYOK) cho X/Twitter.
Các giới hạn quan trọng
- Chỉ các tweets từ khoảng 7 ngày gần nhất mới có sẵn (giới hạn của X API).
- Giới hạn mặc định 25 lệnh gọi mỗi ngày.
- Yêu cầu khóa BYOK cho X/Twitter.
Tham số Header
Tham số Query
string
bắt buộc
Truy vấn tìm kiếm từ khóa. Hỗ trợ các toán tử tìm kiếm của X/Twitter (xem bảng bên dưới).Ví dụ:
ayrshare, #socialmedia, ayrshare OR #socialmedia, from:ayrshare.string
bắt buộc
Phải là
twitter.integer
mặc định:15
Số lượng tweets tối đa được trả về. Phải nằm trong khoảng từ 10 đến 100.
string
Trả về các tweets có ID lớn hơn (mới hơn) giá trị này. Hữu ích để chỉ lấy các tweets mới kể từ yêu cầu trước.
string
Trả về các tweets có ID nhỏ hơn (cũ hơn) giá trị này. Hữu ích để phân trang ngược qua các kết quả.
string
Token phân trang từ
meta.pagination.next của phản hồi trước. Sử dụng token này để lấy trang kết quả tiếp theo.Toán tử Tìm kiếm
Tham sốquery hỗ trợ các toán tử tìm kiếm X/Twitter sau:
| Toán tử | Mô tả | Ví dụ |
|---|---|---|
AND | Cả hai thuật ngữ phải xuất hiện (hành vi mặc định) | social AND media |
OR | Một trong hai thuật ngữ phải xuất hiện | ayrshare OR socialmedia |
from: | Các tweets từ một người dùng cụ thể | from:ayrshare |
to: | Các tweets được gửi tới một người dùng cụ thể | to:ayrshare |
# | Khớp một hashtag | #socialmedia |
@ | Khớp một đề cập | @ayrshare |
- | Loại trừ một thuật ngữ | social -spam |
lang: | Lọc theo ngôn ngữ | ayrshare lang:en |
filter: | Lọc theo loại nội dung | ayrshare filter:links |
url: | Khớp một URL | url:ayrshare.com |
curl \
-H "Authorization: Bearer API_KEY" \
-H "x-twitter-oauth1-api-key: YOUR_TWITTER_API_KEY" \
-H "x-twitter-oauth1-api-secret: YOUR_TWITTER_API_SECRET" \
-X GET "https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15"
const API_KEY = "API_KEY";
fetch(
"https://api.ayrshare.com/api/listen/keyword?query=ayrshare%20OR%20%23socialmedia&platform=twitter&limit=15",
{
method: "GET",
headers: {
Authorization: `Bearer ${API_KEY}`,
"x-twitter-oauth1-api-key": "YOUR_TWITTER_API_KEY",
"x-twitter-oauth1-api-secret": "YOUR_TWITTER_API_SECRET"
}
}
)
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
headers = {
'Authorization': 'Bearer API_KEY',
'x-twitter-oauth1-api-key': 'YOUR_TWITTER_API_KEY',
'x-twitter-oauth1-api-secret': 'YOUR_TWITTER_API_SECRET'
}
params = {
'query': 'ayrshare OR #socialmedia',
'platform': 'twitter',
'limit': 15
}
r = requests.get('https://api.ayrshare.com/api/listen/keyword', headers=headers, params=params)
print(r.json())
{
"status": "success",
"platform": "twitter",
"query": "ayrshare OR #socialmedia",
"tweets": [
{
"id": "1234567890",
"text": "Just discovered @ayrshare for managing social media APIs!",
"createdAt": "2026-03-22T14:30:00.000Z",
"user": {
"id": "987654321",
"name": "Jane Doe",
"screenName": "janedoe",
"profileImageUrl": "https://pbs.twimg.com/profile_images/..."
},
"metrics": {
"retweetCount": 5,
"favoriteCount": 12
},
"entities": {
"hashtags": ["socialmedia"],
"mentions": ["ayrshare"],
"urls": []
},
"inReplyToStatusId": null,
"isRetweet": false,
"lang": "en"
}
],
"meta": {
"pagination": {
"hasMore": true,
"next": "b26v89c19zqg8o3fpds7h...",
"limit": 15
}
}
}
{
"status": "error",
"code": 101,
"message": "Missing or incorrect parameters. Please verify with the docs.",
"details": "The 'query' parameter is required."
}
{
"status": "error",
"code": 401,
"message": "Unauthorized. BYOK keys for X/Twitter are required.",
"details": "Please set up your X/Twitter API keys. See https://docs.ayrshare.com/dashboard/connect-social-accounts/x-twitter-byo-keys"
}
{
"status": "error",
"code": 429,
"message": "Rate limit exceeded. Daily limit of 25 keyword search calls reached.",
"details": "Please try again tomorrow or contact support for higher limits."
}
⌘I
