Closed DlgzRogelio closed 3 years ago
This function is more elaborated, because when the user enters a name, the program will show filtered results related with the input like: Filmography and rating of the actor.
let api_key = '94f0c60308f2a42f4c8a0265000556cd';
let submit_button = document.getElementById( 'submit');
function api_tmdb() {
submit_button.addEventListener('click',function(event) {
event.preventDefault();
let input_actor = document.getElementById('name').value;
let request_movie = 'https://api.themoviedb.org/3/search/person?api_key=' + api_key + '&language=en-US&query=' + input_actor + '&page=1&include_adult=false';
console.log('Results related to: ' + input_actor.toUpperCase());
fetch(request_movie).then(function (response) {
return response.json();
})
.then(function(data) {
let obj_id = data.results;
for (let artist in data.results) {
let id = data.results[artist].id;
let name = data.results[artist].name;
let popularity = data.results[artist].popularity;
let link = 'https://api.themoviedb.org/3/search/person?api_key=' + api_key + '&language=en-US&query=' + name.replace(/ /g, '%20') + '&page=1&include_adult=false';
console.log('NAME: ' + name + ' #' + id + ', ' + link + ' RATED: ' + popularity );
}
});
});
}
api_tmdb();
You may find useful to look for the previous versions to understand how I got to this solution: #18 & #11
Team, let me know if you have any comments about the code. cc @ltrevino @DlgzRogelio @ian-dot
11