twittertwitterapi-pythontwitter-api-v2

Count difference between tweets/count/recent and tweets/search/recent


I am fetching tweets from twitter using APIv2.

To maintain the credibility of data first I am using https://api.twitter.com/2/tweets/counts/recent to get count of tweets for a particular query. Later I am using same parameters/query for fetch the tweets for same duration using https://api.twitter.com/2/tweets/search/recent However, while fetching tweets I am getting less count than I got in count API.

Example:

query parameters for count:
query_params_counts = {"query": "keyword -is:retweet  lang:en",
              "granularity":"day",
              "start_time":"2022-05-09T00:00:00.000Z",
              "end_time":"2022-05-010T00:00:00.000Z"
              } 

for this count is coming: 1766


query_params_tweets = {"query":"keyword -is:retweet  lang:en",
            "start_time":"2022-05-09T00:00:00.000Z",
            "end_time": "2022-05-010T00:00:00.000Z",
            "max_results": 100,
            "expansions": "author_id,attachments.media_keys,entities.mentions.username",
            "tweet.fields": "id,text,created_at,attachments,public_metrics",
            "user.fields": "id,name,username,created_at,description,profile_image_url,location,public_metrics,url",
            "place.fields": "full_name,id,country,country_code,geo,name,place_type",
            "media.fields": "media_key,type,url",
            "next_token": {}
            }

for this count is: 1751

I tried running multiple times but result remained same. Could someone please help me understand what could be the reason for this?


Solution

  • This is explained in the docs:

    Please note: The counts will not always match the result that will be returned from search endpoints because the search endpoints go through additional compliance that the counts endpoints do not go through