Reputation: 1840
Learning how to connect an API up using The Movie Database with JSON. Right now I'm able to call the database and return "poster_path", "original_title", and "release_date". I found a ton of questions on how to hook the call up but nothing specifically that tells me how to get a movie overview. I'm also a bit fuzzy following their provided documentation.
What I would like to do is return the "overview" of each movie. Currently I do not see an overview param in the array objects when I do a console.log(json).
Example of what I would like to return can be found on any movie page Expendables 3, under overview section on a movie page.
$(document).ready(function(){
var url = 'http://api.themoviedb.org/3/',
mode = 'search/movie?query=',
input,
movieName,
key = '&api_key=<api_key>';
$('#search').on('click', function() {
var input = $('#term').val(),
movieName = encodeURI(input);
$.ajax({
type: 'GET',
url: url + mode + input + key,
async: false,
jsonpCallback: 'testing',
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
jQuery.each(json.results, function (key, val) {
/*playing around with different keywords "overview", "primary_info" and others I randomly inserted and all returned undefined*/
/*console.log(json.results[key].poster_path);
console.log(json.results[key].original_title);
console.log(json.results[key].release_date);*/
console.log(json);
});
},
error: function(e) {
console.log(e.message);
}
}).done(function(){
$('.movieSearch').find("input[type=text]").val("");
});
});
});
Any help is greatly appreciated, and if more information is needed in solving this problem will gladly provide.
Upvotes: 1
Views: 1274
Reputation: 1840
Thanks for the help guys. I was able to run a second AJAX call in the success function of the first AJAX call. Then I grabbed the ID of the object I needed the "overview" for, passed that through the url and obtained the correct overview param.
$.ajax({
type: 'GET',
url: url + mode + input + key,
async: false,
cache: false,
jsonpCallback: 'testing',
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
jQuery.each(json.results, function (key, val) {
console.log(json.results[key].id);
});
console.log(json);
var first = json.results[0].id;
console.log(first);
$.ajax({
type: 'GET',
url: url + 'movie/' + first + '?' + key,
async: false,
cache: false,
jsonpCallback: 'testing',
contentType: 'application/json',
dataType: 'jsonp',
success: function(json) {
console.log(json.overview);
},
error: function(e) {}
}).done();
},
error: function(e) {}
}).done();
Again thanks for the help guys and getting me on the right path.
Upvotes: 2
Reputation: 450
Because there is no json.requests. You can access property of json through dot notation.
success: function(json) {
console.log(json);
console.log(json.poster_path);
console.log(json.production_companies.name);
},
Upvotes: 1
Reputation: 21482
It looks like you are making a /search/movie?query={phrase}
call. That call will return summary information for a list of movies that match the query. An id
value is returned for each movie in the list. You can then use that id
in a subsequent /movie/{id}
call to get the details for the movie. The details will include the overview.
Upvotes: 1