Twitter API - Display all tweets with a certain hashtag?

前端 未结 3 1250
别跟我提以往
别跟我提以往 2020-11-30 19:43

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

相关标签:
3条回答
  • 2020-11-30 19:57

    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

    0 讨论(0)
  • 2020-11-30 20:01

    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

    0 讨论(0)
  • 2020-11-30 20:11

    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.

    0 讨论(0)
提交回复
热议问题