Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.   $(function() {
  2.  
  3.     'https://api.themoviedb.org/3/discover/movie?'
  4.     var baseUrl = "https://api.themoviedb.org/3/discover/movie/";
  5.     //var baseUrl = "https://api.themoviedb.org/3/movie/";
  6.     /*I NEED TO MOVE THE BELOW API KEY INTO THE BACKEND!!!*/
  7.     var apiKey = "?page=1&include_video=false&include_adult=false&sort_by=popularity.desc&language=en-US&api_key=45ddf563ac3fb845f2d5c363190d1a33"; //Include adult = false still shown pornographic material?
  8.     //var rng = (Math.floor(Math.random() * 520271) + 1);
  9.     var APIurl = baseUrl + apiKey; /*+ rng +*/
  10.  
  11.     console.log("Url it is loading the data from: " + APIurl);// for testing / debugging
  12.  
  13.     fetch(new Request(APIurl))
  14.       .then(response => {
  15.         if (response.status === 200) return response.json();
  16.         else throw new Error('No film found or no response from the API server!!!');
  17.       })
  18.       .then(feed => {
  19.         let item = '<li class="list-group-item">';
  20.         item += '<img class="center-block img-fluid" alt="Movie Poster Image" src="' + 'http://image.tmdb.org/t/p/w500' + feed.results[0].poster_path + '" alt="">'
  21.         console.log("Full image path: " + 'http://image.tmdb.org/t/p/w500' + feed.results[0].poster_path); // for testing / debugging
  22.         item += '<br>' + '<br>' + '<strong>' +"Title of film / movie: " + '</strong>' + feed.title;
  23.         console.log("Title of film / movie: " + feed.results[0].title); // for testing / debugging
  24.         item += '<br>' + '<br>' + '<strong>' + "Overview / description of film: " + '</strong>' + feed.overview;
  25.         console.log("Overview / description of film: " + feed.overview)
  26.        
  27.        
  28.         let genre = feed.genres.length ? feed.genres[0].name : '';
  29.  
  30.         if (genre) {
  31.         item += '<br>' + '<br>' + '<strong>' + "Genre of film / movie: " + '</strong>' +  feed.genres[0].name;
  32.         console.log("Genre of film / movie: " + feed.genres[0].name);
  33.         } else {
  34.         item += '<br>' + '<br>' +  '<strong>' + "No genre defined: " + '</strong>' + "undefined";
  35.         console.log("No genre defined (undefined)");
  36.         }
  37.  
  38.        
  39.  
  40.         item += '</li>';
  41.  
  42.         $('#feed').append(item);
  43.       });
  44.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement