Search code examples
pythontwittertwitter-search

Twitter search API: search by tweet id


I'd like send query to twitter search API using the tweet id but it seems you cannot search a tweet by having its id (maybe because you don't need to search it if you already have the id). For example imagine we have a tweet https://twitter.com/great_watches/status/643389532105256961 and we want to send 643389532105256961 to the search API to see if the tweet is available on the search api or not.

I need it because I just want to compare twitter search api with twitter streaming api. I have a python script which is listening to the stream for some keywords and whenever a tweet is comming I like to search it on twitter search api to see if it is available there also or not. meaningless huh?


Solution

  • You can't compare the the Search API to the Streaming API the way you're doing it due to the fact they're both retrieving different types of information.

    From the Search API docs:

    The Twitter Search API is part of Twitter’s v1.1 REST API. It allows queries against the indices of recent or popular Tweets and behaves similarily to, but not exactly like the Search feature available in Twitter mobile or web clients, such as Twitter.com search.

    Before getting involved, it’s important to know that the Search API is focused on relevance and not completeness. This means that some Tweets and users may be missing from search results. If you want to match for completeness you should consider using a Streaming API instead.

    Here's to explain the scenario based on the information you've given.

    1. You're streaming the word python and you find a match.
    2. You instantly take that match and look for it on search API

    The issue with that is by the time you're going from Streaming API (which is in real time) and you're looking to find the same one on the search API you'll get in conflict where more relevant tweets and popular one that will supersede it.

    You'll need to redefine the query sent to the search API to include that exact same one (i.e. include more than python as you have done with the Streaming API).