Twitter API - Display all tweets with a certain hashtag?

Twitter

Twitter Problem Overview


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.

Twitter Solutions


Solution 1 - Twitter

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 Entities

> Returns 5 mixed results with Twitter.com user IDs plus entities for the term "blue angels": > > GET http://search.twitter.com/search.json?q=blue%20angels&rpp=5&include_entities=true&with_twitter_user_id=true&result_type=mixed

Solution 2 - Twitter

UPDATE for v1.1:

Rather than giving q="search_string" give it q="hashtag" in URL encoded form to return results with HASHTAG ONLY. So your query would become:

    GET https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames

%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 and max_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

Solution 3 - Twitter

The 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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionProbocopView Question on Stackoverflow
Solution 1 - TwitterQuentinView Answer on Stackoverflow
Solution 2 - TwitterDevaroopView Answer on Stackoverflow
Solution 3 - TwitterCraig MylesView Answer on Stackoverflow