Skip to main content

Advanced Tweet Search (POST /search-tweets)

What is it? The /search-tweets endpoint replicates the full power of the X (Twitter) Advanced Search engine. It allows you to search for specific tweets using a wide array of filters and logic, returning up to 20 matching tweets per request. Why use it?
  • Trend Monitoring: Track specific keywords or hashtags to gauge public sentiment in real-time.
  • Competitor Analysis: Use operators like from:handle to monitor all posts from a specific competitor.
  • Date-Range Research: Collect historical data for specific events using since:YYYY-MM-DD and until:YYYY-MM-DD operators.
  • Brand Protection: Monitor mentions of your brand or specific product phrases to respond to customer feedback quickly.
Technical Details:
  • Sorting: Results can be ordered by popular or latest.
  • Pagination: If more than 20 results exist, the API returns a next_cursor to fetch the next page.
  • Query Syntax: Supports standard X operators (e.g., from:, to:, exact phrases, #hashtags).
Python Implementation:
import requests

API_KEY = "YOUR_API_KEY"
URL = "https://api.sorsa.io/v3/search-tweets"

payload = {
    "query": "bitcoin since:2024-01-01",
    "order": "popular",  # Options: 'popular' or 'latest'
    "next_cursor": ""    # Leave empty for the first request
}

headers = {
    "ApiKey": API_KEY,
    "Content-Type": "application/json"
}

response = requests.post(URL, json=payload, headers=headers)
data = response.json()

for tweet in data.get('tweets', []):
    print(f"[{tweet['created_at']}] {tweet['user']['screen_name']}: {tweet['full_text'][:50]}...")