According to the documentation, exact phrase searches should be possible using double-quoting (as per the Search Operators section here: Twitter API Documentation | Docs | Twitter Developer Platform). However, I am not able to get it to work. For example, I am trying to search for the name “Al Maag”. Using the website search works just fine, eg here is a URL which shows plenty of tweets:
https://twitter.com/search?q="Al%20Maag"&mode=relevance&src=typd
But when I try to do the same search using the api, I get no results. eg I generated this test curl command using the oauth signing tool (removed oauth headers to keep it secure):
curl --get ‘https://api.twitter.com/1.1/search/tweets.json’ --data ‘count=4&max_id=250126199840518145&q=%22Al+Maag%22&result_type=mixed&since_id=24012619984051000’
How can I successfully search for an exact phrase on the api?
episod
#2
I think the query is working for you in both contexts – the difference just is is that the Search API’s index only goes back around one week while the webstie has access to additional indexes. The last tweet matching this exact term was enough days ago that it’s no longer indexed.
Ah yes, that seems to be the case. Thanks!
I have this problem with just a specific phrase!, other phrases work.
Can anyone please explain why this query does not return any tweet?
curl --location --request GET ‘https://api.twitter.com/1.1/search/tweets.json?q=“شهدای%20پاکدشت”’ --header ‘Authorization: OAuth oauth_consumer_key=““,oauth_token=””,oauth_signature_method=“HMAC-SHA1”,oauth_timestamp=““,oauth_nonce=””,oauth_version=“1.0”,oauth_signature=“***”’ --compressed
Try URL encoding the query if it contains non ascii characters:
If the query is "شهدای پاکدشت" (with quotes)
the url should be
/1.1/search/tweets.json?q=%22%D8%B4%D9%87%D8%AF%D8%A7%DB%8C%20%D9%BE%D8%A7%DA%A9%D8%AF%D8%B4%D8%AA%22
(that specific phrase has no recent results in the last 7 days so you won’t get any results from the search API)