Majico
Majico

Reputation: 3830

Twitter RestAPI call from java using space and OR

In this link, it has been explained how to use the Twitter search API, for example: Your search URL is:

https://api.twitter.com/1.1/search/tweets.json?q=superman OR spiderman&result_type=recent

when I do a GET call using the link from POSTMAN (setting OAuth 1 params)it works fine, but when i do the same GET call from JAVA, it gives me the following error:

Caused by: java.net.URISyntaxException: Illegal character in query at index 57: https://api.twitter.com/1.1/search/tweets.json?q=superman OR spiderman&result_type=recent
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)

it works fine if i just search with one word without space and OR.

Upvotes: 0

Views: 39

Answers (1)

Jonas
Jonas

Reputation: 4048

It sounds like you need to encode the URL properly. For instance a space character must be replaced with %20. Here is a table of encodings. Really, you should use a built in function. See this thread.

Upvotes: 1

Related Questions