22 Kudos

I recently need to get a JSON object from Twitter’s API that had a couple of requirements. I needed the most recent tweets that contained a specific hashtag OR were from a specific user AND didn’t contain any retweets.

Starting with the base API URL for search


Then appending each piece of the search as required

https://api.twitter.com/1.1/search/tweets.json?q=from:example OR #example
https://api.twitter.com/1.1/search/tweets.json?q=from:example OR #example + exclude:retweets

Then a proper URL encode results in


TIP: To find out what the URL should be after the ?q= do a search how you would like on https://twitter.com/search or https://twitter.com/search-advanced and copy of the tail end of the URL and stick it onto yours.