I'm trying to do something that seems like it should be simple. Get the input of a text field and search the themoviedb.org database for it via the API.
I'm using jQuery and the themoviedb.org APIv3, which supports JSONP. All I get, though, is this response:
{"status_code":6,"status_message":"Invalid id - The pre-requisite id is invalid or not found"}
That doesn't really tell me a lot. ID of what?
Things I know:
Here's a jsfiddle, and here's the API documentation about searching movies. Also, check out this version of the API docs. I think it has to do with the query params.
Really, I have no idea what I'm doing with JSON, so I'm hoping this will be a representative example that will help me understand it.
You just need the correct number of query string parameters. The required paramaters are query
and api_key
. I found these requirements here http://docs.themoviedb.apiary.io/#get-%2F3%2Fsearch%2Fmovie. Give this a try instead:
$(document).ready(function() {
var url = 'http://api.themoviedb.org/3/',
mode = 'search/movie?query=',
input,
movieName,
key = '&api_key=470fd2ec8853e25d2f8d86f685d2270e';
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.ajax({
type: 'GET',
url: url + mode + input + key,
async: false,
jsonpCallback: 'testing',
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
console.dir(json);
},
error: function(e) {
console.log(e.message);
}
});
});
});
Working Fiddle: http://jsfiddle.net/fewds/srdHD/3/
Note: Since thats most likely your REAL api key I would suggest requesting a new one!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With