The Movie Database Support

Hi, I have a problem where my movie search code is often returning an empty result.
I am iterating through a list of movies in Java as in the below snippet...
This generally works but more often than not returns an empty result.

The below code randomly returns an empty result eg...

Movie search URL: https://api.themoviedb.org/3/search/movie?api_key=3bbe736fb......&query="Pirates Of The Caribbean 1 - The Curse Of The Black Pearl"
Movie search response :<{"page":1,"total_results":0,"total_pages":0,"results":[]}>
Movie JSON data in string format
{"page":1,"total_results":0,"total_pages":0,"results":[]}

Or returns a correct result eg...
Movie search URL: https://api.themoviedb.org/3/search/movie?api_key=3bbe736fb......&query="Gladiator"
Movie search response :<{"page":1,"total_results":41,"total_pages":3,"results": [{"popularity":42.718,"vote_count":11567,"video":false,"poster_path":"\/dvKsQB84W2Sv6s7jpGmzQBVyQe3.jpg","id":98,"adult":false,"backdrop_path":"\/.......

Either way, if I cut/paste the search URL into a browser I get the correct result.

Any ideas or help would be greatly appreciated.

Code snippet

                URL url = new URL(searchUrl);  
                HttpURLConnection conn = (HttpURLConnection)url.openConnection();   
                conn.setRequestMethod("GET");  
                conn.setRequestProperty("Content-Type", "application/json");  
                conn.connect();  
                int responsecode = conn.getResponseCode();  
                if(responsecode != 200) {  
                    System.out.println("RESPONSE CODE: "+responsecode);  
                    throw new RuntimeException("HttpResponseCode: " +responsecode);  
                }  

                Scanner sc = new Scanner(url.openStream());  
                while(sc.hasNext()) {  
                    tempLine=sc.nextLine();  
                    System.out.println("Movie search response :<"+tempLine+">");  
                    inLine+=tempLine;  
                }  
                sc.close();

2 replies (on page 1 of 1)

Jump to last post

Are you url encoding the title? For example I noticed that "pirates of the caribbean" has spaces in it and "gladiator" does not. Spaces when url encoded are %20. This may work in the browser as the browser may url encode the address before sending the request.

@Knossos , thank you very much for your help. This was exactly my problem and all is working well now...

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login