How would I go about displaying tweets that contain a certain hashtag using the Twitter API? Thanks
I'd also like to know if there is a way to get all tweets from a certain hashtag in a separate file, also the ones that don't show up in your feed anymore. I suppose that's what the earlier question was about, too.
This answer was written in 2010. The API it uses has since been retired. It is kept for historical interest only.
Search for it.
Make sure
include_entities
is set to true to get hashtag results. See Tweet EntitiesThe answer here worked better for me as it isolates the search on the hashtag, not just returning results that contain the search string. In the answer above you would still need to parse the JSON response to see if the entities.hashtags array is not empty.
UPDATE for v1.1:
Rather than giving
q="search_string"
give itq="hashtag"
in URL encoded form to return results with HASHTAG ONLY. So your query would become:%23
is URL encoded form of#
. Try the link out in your browser and it should work.You can optimize the query by adding
since_id
andmax_id
parameters detailed here. Hope this helps !Note: Search API is now a OAUTH authenticated call, so please include your access_tokens to the above call
Updated
Twitter Search doc link: https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets.html