public function testSearchActor() { /** * @covers \ */ $config = parse_ini_file('./api.ini'); $tmdb = new TMDB($config['apikey'], 'en'); $actors = $tmdb->searchPerson("johnny knoxville"); $this->assertCount(1, $actors); }
<?php include 'tmdb-api.php'; $root_name = "data"; $array = array(); if (!isset($_REQUEST['query']) || TRIM($_REQUEST['query']) == '') { $array["opcion"] = 2; $array["status_message"] = "The resource you requested could not be found."; echo json_encode($array); } else { $apikey = 'b452a69cd4b748e4c41a4109f4d91f8f'; $tmdb = new TMDB($apikey); // by simply giving $apikey it sets the default lang to 'en' $name = $_REQUEST['query']; $persons = $tmdb->searchPerson($name); $array["opcion"] = 1; if (sizeof($persons) == 0) { $array["results"] = array(); } else { foreach ($persons as $person) { $persona = $tmdb->getPerson($person->getID()); $know_for = array(); $movies = $persona->getMovieRoles(); for ($i = 0; $i < sizeof($movies) && $i < 4; $i++) { $know_for[] = array("title" => $movies[$i]->getMovieTitle()); } $personaje = array("name" => $persona->getName(), "id" => $persona->getID(), "known_for" => $know_for, "profile_path" => $persona->getProfile()); $array["results"][] = $personaje; } } echo json_encode($array);
<!DOCTYPE html> <html> <head> <title>API usage for Persons</title> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta charset="utf-8" /> </head> <body> <?php include "../tmdb-api.php"; $apikey = "Your API Key"; $tmdb = new TMDB($apikey, 'en', true); echo '<h2>API Usage for Persons examples</h2>'; // 1. Search Person echo '<ol><li><a id="searchPerson"><h3>Search Person</h3></a><ul>'; $persons = $tmdb->searchPerson("Johnny"); foreach ($persons as $person) { echo '<li>' . $person->getName() . ' (<a href="https://www.themoviedb.org/person/' . $person->getID() . '">' . $person->getID() . '</a>)</li>'; } echo '</ul></li><hr>'; // 2. Full Person Info echo '<li><a id="personInfo"><h3>Full Person Info</h3></a><ul>'; $person = $tmdb->getPerson(85); echo 'Now the <b>$person</b> var got all the data, check the <a href="http://code.octal.es/php/tmdb-api/class-Person.html">documentation</a> for the complete list of methods.<br><br>'; echo '<b>' . $person->getName() . '</b><ul>'; echo ' <li>ID: ' . $person->getID() . '</li>'; echo ' <li>Birthday: ' . $person->getBirthday() . '</li>'; echo ' <li>Popularity: ' . $person->getPopularity() . '</li>'; echo '</ul>...'; echo '<img src="' . $tmdb->getImageURL('w185') . $person->getProfile() . '"/>'; echo '</ul></li><hr>';
} else { if ($_GET['search'] === 'Search' and isset($_GET['searchterm'])) { $searchterm = filter_var($_GET['searchterm'], FILTER_SANITIZE_ENCODED); // had issues with filter_var returning nullset so we make sure that we have data if (isset($searchterm) and $searchterm != false) { $tmdb = new TMDB($config['apikey'], 'en'); if ($_GET['type'] === 'Movie') { $movies = $tmdb->searchMovie($searchterm); if (count($movies) > 0) { // I like proper formatting in pages. It makes it easier on the eyes print_movieresults($movies); } else { echo '<p class="error">No Movies found with the terms ', $searchterm, '</p>'; } } elseif ($_GET['type'] === 'Actor') { $actors = $tmdb->searchPerson($searchterm); if (count($actors) > 0) { // I like proper formatting in pages. It makes it easier on the eyes print_actorresults($actors); } else { echo '<p class="error">No Actors found with the terms ', $searchterm, '</p>'; } } } } else { print '<p class="error">Error: Invalid search terms were passed</p>'; } } print_footer(); ?>