DlgzRogelio / Project-1

MIT License
0 stars 1 forks source link

TMDB API: Fetch filmography, name & rating #22

Closed DlgzRogelio closed 3 years ago

DlgzRogelio commented 3 years ago

11

ca2los commented 3 years ago

Actor + Filmography + Rating

ATTENTION: This code is just an initial approach of the program. For further updates, plz visit #23

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.

@CONSOLE
    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