Searchquery operators



When I query the API method ‘search/tweets’ (GET) with as parameter q = ‘Twitter’ it’s doing just fine (I get back a list of tweets containing the word Twitter). When I try adding the OR operator and update the query (q parameter) to ‘Twitter OR Facebook’, the call fails. I get back a 400 error (Call failed). The documentation states that there must be something wrong with the authentication (, but I highly doubt that since I only changed the searchquery and before that it worked just fine.

The above query is just an example (but it’s also tested and not working), in my real application the query uses a few more operators. For these tests I removed all other parameters and only use the required ‘q’ parameter.

Update: Only using ‘Twitter Facebook’ isnt working either. Both with and without url encoding. When I try any of these queries on they just work fine (they also work on the ‘old’ Twitter search API endpoint.)

Any suggestions are welcome. Thank you in advance.

  • Jordi


It’s likely due to parameter encoding invalidating your signature. Make sure that when you use space characters – and really just about any of the very few non-reserved characters – that you’re encoding them validly for query string. Our OAuth and HTTP implementations in API v1.1 are strict and will not accept unencoded characters that are reserved.


Before sending the q parameter I use PHP’s urlencode. The space is just a regular space. I’ll dive deeper in the used framework to see what exactly is happening there…

Current function is using rawurlencode (PHP) which returns the string in RFC3986, which is the same as stated in the Twitter V1.1 API docs. In the previous API the following worked: str_replace(’+’, ’ ‘, str_replace(’%7E’, ‘~’, rawurlencode(($string)))); For as far as I know this is still correct and should work.

Update 2:
Finally found the solution: I’m using a PHP framework for Codeigniter (made by elliothaughin, Github). And this framework double encodes the params for some reason. Seems like this was no problem for de V1 API, but it does make a difference for the V1.1 API. For those searching for the specific fix: Remove/comment out line 587 ($v = $this->_encode_rfc3986($v);). Because 3 lines below 587 the concatenated params are encoded (again).

When using the framework from your own Codeigniter code, make sure to use rawurlencode for your parameter values (q=value)