AI Development

    How to build a tweet search web app

    By Desearch Editorial Team5 min read

    I wanted a tweet search on a single page, where anyone can search public X posts with filters, without an X account or a developer app. It took one Desearch endpoint and about 300 lines of standard-library Python.

    The worked example is Search public X posts with filters. View the code in the Desearch Python examples repo.

    The basics

    • Base URL: https://api.desearch.ai
    • Auth: Authorization: $DESEARCH_API_KEY (the raw key from Desearch Console)
    • Endpoint: GET /twitter

    Get a key

    Sign up in the Desearch console, create an API key, and export it as DESEARCH_API_KEY.

    BASH
    export DESEARCH_API_KEY=your_key

    The page sends that value on the request. It does not write the key into the HTML.

    Make one call

    BASH
    curl -H "Authorization: $DESEARCH_API_KEY" \
      "https://api.desearch.ai/twitter?query=bitcoin&sort=Latest&count=20&lang=es"

    You get a JSON list of posts with text, time, language, like, reply and repost counts, media and author flags.

    Map the form to parameters

    Each filter in my form is one query parameter.

    Form fieldParameter
    Sortsort
    Countcount
    Languagelang
    Min likesmin_likes
    Min repliesmin_replies
    Min repostsmin_retweets
    Verifiedverified
    Blue verifiedblue_verified
    Videois_video
    Imageis_image
    Quoteis_quote
    Start datestart_date
    End dateend_date

    For "any of these words" I build (a OR b) and always keep the parentheses.

    Use blue_verified for blue-check accounts. For recent top posts, add a start date.

    If the query is a hashtag, the operators are in how to search hashtags on X. The product page for this endpoint is X Search.

    Check the form before you call

    I check the form before the call so a bad form does not waste a request. The app rejects a blank query, a count outside 1 to 100, reversed or future dates, and negative numbers before it sends anything.

    Show results and a CSV

    Each row has time, text, likes, replies, and a link in x.com/i/status/<id> form. The same search can be downloaded as CSV.

    What I saw

    • I tested each filter with the same query. Language, min likes, min replies, min reposts, blue verified, video, quote and date range all narrowed the latest 20 public posts Desearch returned.
    • A 20-post search took 1.5 to 6.4 s and cost $0.003.

    Frequently asked questions

    How do I search for any of several words?

    For "any of these words" I build (a OR b) and always keep the parentheses.

    How do I ask for blue-check accounts?

    Use blue_verified. For recent top posts, add a start date.

    What does the page reject before it calls?

    A blank query, a count outside 1 to 100, reversed or future dates, and negative numbers. The check runs first so a bad form does not waste a call.

    Where is the code?

    View the code in the tweet-search-web-app folder. The same app is Search public X posts with filters.

    Related examples: Twitter account lookup app for X, Launch video swipe file from X in Python.

    Put your next idea to work.

    Try a query in the playground, then use the docs to bring Desearch into your application.

    Browse more articles