Giter Club home page Giter Club logo

tmdb_v3-php-api-'s Introduction

Documentation

Documentation

Join the chat at https://gitter.im/pixelead0/tmdb_v3-PHP-API-

TMDB API v3 PHP Library - wrapper to API version 3 of themoviedb.org.

For using this library maybe you should take a look at the full Documentation of this project.

@package TMDB-V3-PHP-API
@author Pixelead0 also on Github
@author Alvaro Octal also on Github
@author Deso85 also on Github
@date 02/04/2016
@version 0.5

CREDITS

Forked from a similar project by Jonas De Smet

CHANGE LOG

  • [18/06/2017] v0.6

    • Implemented function for multiSearch
    • Added example for multiSearch
    • Fixed examples
  • [02/04/2016] v0.5

    • Made a class for configuration to load external configs
    • Updated functions list
    • Changed a few functions to use config object
    • Changed package structure of the project
  • [01/04/2016] v0.4

    • Added config file
    • Some code changes to use config file
    • Some formal corrections inside comments
    • (Hopefully) Corrected Versioning
  • [17/01/2015] v0.3 - Upgraded by

  • [07/11/2012] v0.2

    • Fixed issue #2 (Object created in class php file)
    • Added functions latestMovie, nowPlayingMovies (thank's to steffmeister)
  • [12/02/2012] v0.1

    • This is the first version of the class without inline documentation or testing
    • Forked from glamorous/TMDb-PHP-API

Requirements

  • PHP 5.2.x or higher
  • cURL
  • TMDB API-key

How to use

View examples

Initialize the class

If you have a $conf array

<?php
	include('tmdb-api.php');
	
	// if you have a $conf array - (See LIB_ROOT/configuration/default.php as an example)
	$tmdb = new TMDB($conf);
	
?>

If you have no $conf array it uses the default conf but you need to have an API Key

<?php
	include('tmdb-api.php');
	
	// if you have no $conf it uses the default config
	$tmdb = new TMDB(); 
	
	//Insert your API Key of TMDB
	//Necessary if you use default conf
	$tmdb->setAPIKey('YOUR_API_KEY');
	
?>

Movies

Search a Movie

<?php
	//Title to search for
	$title = 'back to the future';
	$movies = $tmdb->searchMovie($title);
	// returns an array of Movie Object
	foreach($movies as $movie){
		echo $movie->getTitle() .'<br>;
	}
?>

returns an array of Movie Objects.

Get a Movie

You should take a look at the Movie class Documentation and see all the info you can get from a Movie Object.

<?php
	$idMovie = 11;
	$movie = $tmdb->getMovie($idMovie);
	// returns a Movie Object
	echo $movie->getTitle();
?>

returns a Movie Object.

TV Shows

Search a TV Show

<?php
	// Title to search for
	$title = 'breaking bad';
	$tvShows = $tmdb->searchTVShow($title);
    foreach($tvShows as $tvShow){
        echo $tvShow->getName() .'<br>';
	}
?>

returns an array of TVShow Objects.

Get a TVShow

You should take a look at the TVShow class Documentation and see all the info you can get from a TVShow Object.

<?php
	$idTVShow = 1396;
	$tvShow = $tmdb->getTVShow($idTVShow);
	// returns a TVShow Object
	echo $tvShow->getName();
?>

returns a TVShow Object.

Get a TVShow's Season

You should take a look at the Season class Documentation and see all the info you can get from a Season Object.

<?php
	$idTVShow = 1396;
	$numSeason = 2;
	$season = $tmdb->getSeason($idTVShow, $numSeason);
	// returns a Season Object
	echo $season->getName();
?>

returns a Season Object.

Get a TVShow's Episode

You should take a look at the Episode class Documentation and see all the info you can get from a Episode Object.

<?php
	$idTVShow = 1396;
	$numSeason = 2;
	$numEpisode = 8;
	$episode = $tmdb->getEpisode($idTVShow, $numSeason, $numEpisode);
	// returns a Episode Object
	echo $episode->getName();
?>

returns a Episode Object.

Persons

Search a Person

<?php
	// Name to search for
	$name = 'Johnny';
	$persons = $tmdb->searchPerson($name);
    foreach($persons as $person){
        echo $person->getName() .'<br>';
    }
?>

returns an array of Person Objects.

Get a Person

You should take a look at the Person class Documentation and see all the info you can get from a Person Object.

<?php
	$idPerson = 85;
	$person = $tmdb->getPerson($idPerson);
	// returns a Person Object
	echo $person->getName();
?>

returns a Person Object.

Get Person's Roles

You should take a look at the Role class Documentation and see all the info you can get from a Role Object.

<?php
	$movieRoles = $person->getMovieRoles();
	foreach($movieRoles as $movieRole){
        echo $movieRole->getCharacter() .' in '. $movieRole->getMovieTitle() .'<br>';
    }
?>

returns an array of MovieRole Objects.

<?php
	$tvShowRoles = $person->getTVShow();
	foreach($tvShowRoles as $tvShowRole){
        echo $tvShowRole->getCharacter() .' in '. $tvShowRole->getMovieName() .'<br>';
    }
?>

returns an array of TVShowRole Objects.

Collections

Search a Collection

<?php
	// Name to search for
	$name = 'the hobbit';
	$collections = $tmdb->searchCollection($name);
	foreach($collections as $collection){
		echo $collection->getName() .'<br>';
	}
?>

returns an array of Collection Objects.

Get a Collection

You should take a look at the Collection class Documentation and see all the info you can get from a Collection Object.

<?php
	$idCollection = 121938;
	$collection = $tmdb->getCollection($idCollection);
	// returns a Collection Object
	echo $collection->getName();
?>

returns a Collection Object.

Companies

Search a Company

<?php
	// Name to search for
	$name = 'Sony';
	$companies = $tmdb->searchCompany($name);
	foreach($companies as $company){
		echo $company->getName() .'<br>';
	}
?>

returns an array of Company Objects.

Get a Company

You should take a look at the Company class Documentation and see all the info you can get from a Company Object.

<?php
	$idCompany = 34;
	$company = $tmdb->getCompany($idCompany);
	// returns a Company Object
	echo $company->getName();
?>

returns a Company Object.

Issues/Bugs

Bugs are expected, this is still under development, you can report them.

TODO List

  • Empty :D, you can propose new functionalities.

tmdb_v3-php-api-'s People

Contributors

akeinhell avatar alvaro-octal avatar bogdanfinn avatar buibr avatar deso85 avatar dimitris-ilias avatar djleven avatar emmanuelsimond avatar gitter-badger avatar j-ulian avatar kaeferd avatar marcogomesr avatar mmapes avatar olivier-nolbert avatar pixelead0 avatar revoltek-daniel avatar tharok2090 avatar tnsws avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tmdb_v3-php-api-'s Issues

getImageURL not working

When I call getImageURL() to get an image, I receive the error:

PHP Warning: Undefined array key "images" in /srv/http/StreamableTest/tmdb_v3-PHP-API--master/controller/classes/config/APIConfiguration.php on line 40

why would 'images' not be defined?

Trailer in TV Show

Have copied the code below from Movie class to TVShow class and then I tried to display it on the page with $tvShow->getTrailer(); but nothing appear there. I know that this will (if) display only the filename, but is ok for me.

`
/**
* Get the TVShow's trailers
*
* @return array
*/

public function getTrailers() {
	return $this->_data['trailers'];
}

/** 
 * 	Get the TVShow's trailer
 *
 * 	@return string | null
 */
public function getTrailer() {
	$trailers = $this->getTrailers();

	if (!array_key_exists('youtube', $trailers)) {
		return null;
	}

	if (count($trailers['youtube']) === 0) {
		return null;
	}

	return $trailers['youtube'][0]['source'];
}

`

Maybe it needs to add somewhere append_to_response=video or something else? If yes, where is that declaration?

Thank you
Chris

Notice: Undefined variable

Hello,

I'm using your library and i think i found an issue;

I created a new file

<?php
    $url= "http://api.themoviedb.org/3/movie/1824/trailers?api_key=XXXXXXXXXXXXX";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1);

    $results = curl_exec($ch);
    $headers = curl_getinfo($ch);

    $error_number = curl_errno($ch);
    $error_message = curl_error($ch);

    curl_close($ch);

    $results = json_decode(($results),true);

    print_r(var_dump($results));

?>

and there is some trailer info under the youtube array, as you can see here

array
    'id' => int 1824
    'quicktime' => 
        array
            empty
    'youtube' => 
        array
            0 => 
                array
                    'name' => string 'trailer' (length=7)
                    'size' => string 'Standard' (length=8)
                    'source' => string 'ErjP5xMTc8I' (length=11)

but using the movieTrailer($idMovie) function included on tmdb_v3.php there is not, instead i change the movieTrailer original function to:

public function movieTrailer($idMovie)
    {
    $trailerTmp = $this->movieInfo($idMovie,"trailers",false);
    foreach ($trailerTmp['youtube'] as $trailerArr)
    {
        $trailer[]=$trailerArr['size']." - ".$trailerArr['source'];
    }
    return $trailer;
    }

it returns null and a "Notice: Undefined variable: trailer " on tmdb_v3.php on the line "return $trailer;"

i re-check all the sintaxis, it seems to be ok please let me know what is wrong,

i do the same with the moviePoster function, same results, but the movieTrans function seems to have same array structure and it works just fine

PD: sorry for my bad english

Tv shows

this class is only for movies ?
i need also for tvshows

Empty youtube video problem

Hello

I have a problem with the youtube video displays. When the video exists in a film no worries everything works fine. The problem comes when there is no id of the youtube video I have this error
Notice: Undefined offset: 0 in C:\wamp64\www\pacaprez\engine\inc\class\api\tmdb\controller\classes\data\Movie.php on line 184

Here is the code in question for the error
/** * Get the Movie's trailer * * @return string */ public function getTrailer() { $trailers = $this->getTrailers(); return $trailers['youtube'][0]['source']; }

So I would like to know how to not display when it is empty. Here is the code I use when there is a video
echo '<br /><br /><b>Bande Annonce</b><br /> <iframe width="560" height="315" src="https://www.youtube.com/embed/'. $movie->getTrailer() .'" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen> </iframe><br />';

Thanks for your help and for your script

Undefined index: movie_credits

Hi, is it possible to get cast and crew of movie Persons in the same function like getCredits(); ? I need to create a page with both cast and crew and the role of each person only ? also when I use this code to get all the cast member with their role on the movie it show me the first 40 correct with their role but then i get Undefined index: movie_credits & Invalid argument supplied for foreach() error. I'm still learning PHP so maybe I have approached the solution in a wrong way.

  $tmdb = new TMDB(); 
  $movieId = 383498;
  $tmdb->setAPIKey('APIKEY');
  $movie = $tmdb->getMovie($movieId);
  $cast = $movie->getCast();

   foreach ($cast as $person) {
                                echo '<li>'. $person->getName() .' </li>';
                                echo '<img src="'. $tmdb->getImageURL('w185') . $person->getProfile() .'"/></li>';
                                $person = $tmdb->getPerson($person->getID());
                        $movieRoles = $person->getMovieRoles();
                        foreach($movieRoles as $movieRole){
                            if ($movieRole->getMovieID() == $movieId){
                            echo $movieRole->getCharacter() ;

                                   ;}}}

                            

### The Error

Undefined index: movie_credits in /var/www/html/app/tmdb/controller/classes/data/Person.php on line 122



Warning: Invalid argument supplied for foreach() in /var/www/html/app/tmdb/controller/classes/data/Person.php on line 122

Num of episodes in seasons loop

Hello,

Any idea why the code below in infoTVShow.php return 0 as amount of episodes in seasons loop?
echo '<li>Seasons: <ul>'; $seasons = $tvShow->getSeasons(); foreach ($seasons as $season) { echo '<li><a href="https://www.themoviedb.org/tv/season/'.$season->getID().'">Season '.$season->getSeasonNumber().'</a></li> <li>Air Date: '.$season->getAirDate().'</li> <li>Episodes: '.$season->getNumEpisodes().'</li> <li><img src="'. $tmdb->getImageURL('w185') . $season->getPoster() .'"/></li>'; } echo '</ul></li>
I tried to pass as parameter:
$season->getNumEpisodes($season->getID())
but I had no success.

Thank you
Chris

director name and other fields not picked

Hi, i have tried you php script... but i couldnt get some some fields, like as director or the released year

which changes could I made to get the director name?

thanks

In the README you have bug

"$languaje = 'es';"
need:
"$language = 'es';"

because you used "$language" in "$tmdb = new TMDB($apikey, $language);"

Great class!

just wanted to say that this is a great class and i am enjoying playing with it! I have one sugestion thought ... it would be great if you could add the option to turn on and off the output of the result in the class initialisation like this:

// Init tmdb with debug turned off
$tmdb_V3 = new TMDBv3($_CONFIG['api_key'], false);

Keep up the good work bro ;-)

Unable to read configuration, verify that the API key is valid

API is vaild, but i dont know why i get this error "Unable to read configuration, verify that the API key is valid" but only on free hosting. Local host works normaly (I am creating site only for my personal use).
When i modified line checking api key i got error that say its invaild argument for foreach, but when i clicked on check request its everything there.

Dont know what more to say...
http://www.hostinger.com/ <---- free host

searchMovie() should apply language set

Hi

I think the method searchMovie() should apply the language set by the method setLang() and in the end it should look like this:

public function searchMovie($movieTitle){
$movieTitle="query=".urlencode($movieTitle);
return $this->_call("search/movie",$movieTitle,$this->_lang);
}

What do you guys think about that?

Regards.

A missed quote in README.markdown

Hello, it would seems a missed quote in README.markdown file :

<?php
	//Title to search for
	$title = 'back to the future';
	$movies = $tmdb->searchMovie($title);
	// returns an array of Movie Object
	foreach($movies as $movie){
		echo $movie->getTitle() .'<br>    /!\ HERE /!\    ;
	}
?>

Error when running the example code

Hi,

First off thanks for this wonderful script. I'm getting this issue when testing the examples/moviesExample.php.

Parse error: syntax error, unexpected '[' in /home/main/www/bot/php/tmdb/tmdb/data/Movie.php on line 108

The code for this error is:

107 public function getTrailer() {
108 return $this->getTrailers() ['youtube'][0]['source'];
109 }

I think this might be a php version issue. Any way I could make this complaint with php5.3?

Thank you,

Example File Not Working

I'm getting this error when I use the example file (with my API Key)

Parse error: parse error, expecting `T_FUNCTION' in /Users/sjm/Sites/howt/tmdb_v3.php on line 71

List Action movies

How can I listing Action movies by release date and popularity?

I tried this one but I got error:

public function listGenreAction($page = 1) {
        $movies = array();
        $result = $this->_call('discover/movie?with_genres=18', 'page='. $page);
        foreach($result['results'] as $data){
            $movies[] = new Movie($data);
        }
        return $movies;
    }

(Warning: Invalid argument supplied for foreach() in /inc/tmdb-api.php on line 259)

Object created in class php file

Hi

Why is in tmdb_v3.php, at line 50 already a object created? Shouldn't this be done by the user in his php files? I just got an error just by including the tmdb php, which isn't really good I think.

I suggest removing line 49 and 50 of tmdb_v3.php.
What do you guys think about that?

Regards.

Warning: Illegal string

Hi I seem to get these errors when running the example files

Warning: Illegal string offset 'apikey' in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 42

Warning: Illegal string offset 'lang' in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 43

Warning: Illegal string offset 'adult' in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 45

Warning: Illegal string offset 'debug' in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 46

Warning: Illegal string offset 'appender' in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 48

Warning: Invalid argument supplied for foreach() in /www/sites/tmdb/wwwroot/controller/classes/config/Configuration.php on line 48

search/multi

Hi there,

thanks for this awesome lib.

However, I need to use search/multi but can't find any implementation. Any workaround?

Thanks

Wrong code in readme file

Hello,

The code in the readme file about the search function is wrong.
If I use :

$searchTitle = $tmdb_V3->searchMovie('$title');

its searching for movies with the title "$title".
The code above should be replaced with:

$searchTitle = $tmdb_V3->searchMovie($title);

The title variable isn't between quotes anymore, and thus looking for movies with their title equal to the entered value in $title.

I hope my explanation is clear.

Regards,

Jeroen

How do I get the [character] each actor played in the movie??

Hi,
I successfully got all movie details along with the getCast() array which includes all movie actors along with their information. Among this information is the Character the actor plays in the movie.
How do I get this information??

For example for movie "The Suicide Squad (2021)" with tmdb_id 436969..
This is the info I get for the first actor
Array
(
[0] => Person Object
(
[_data:Person:private] => Array
(
[adult] =>
[gender] => 1
[id] => 234352
[known_for_department] => Acting
[name] => Margot Robbie
[original_name] => Margot Robbie
[popularity] => 84.384
[profile_path] => /euDPyqLnuwaWMHajcU3oZ9uZezR.jpg
[cast_id] => 33
[character] => Harleen Quinzel / Harley Quinn
[credit_id] => 5ca268419251411a16098d23
[order] => 0
)

    )

...and the array continues..

I can get almost all data via the defined functions, for example I get the name of the actor with person->getName()..
How do I get the "character"??

Movie Directors - class Person error

There's an error - Cannot use object of type Person as array - when i try to get directors' ids with Movie::getDirectorsIds(), so it's necessary to add Credits class

getPopularMovies seems to be broken

Not sure if I'm doing it wrong. Here's my code.

            <?php
              $topRentals = $tmdb->getPopularMovies();
              foreach($topRentals as $topRental) {
                echo $topRental->getTitle() . '<br />';
              }
            ?>

Replacing getPopularMovies with nowPlayingMovies displays results.

Display Popular movies

How can I display title, release date and poster of all popular movies from first page?

How to get Movie/TV/Person search page ?

How to get the pages for search so I can connect it to my URL&page=(the number of the search page) ?
I tried to edit this part but I got an error and the same results when I passed the Page number? could you please help me with this ?

public function searchMovie($movieTitle,$page){

 	$movies = array();

 	$result = $this->_call('search/movie', '&query='. urlencode($movieTitle), '&page=' . $page);

 	foreach($result['results'] as $data){
 		$movies[] = new Movie($data);
 	}

 	return $movies;
 }

The Error

Warning: Invalid argument supplied for foreach() in ...\controller\classes\config\Configuration.php on line 48

Thanks

List movie genres in link

Hi!
I tried: "echo $movie->getGenres()" and a got: "Array".
How can I list genres of a link as a link?
I want to list genres names as a link. The link href is the genre id.

List of film genres

I looked a little at the codes and I tried the one you offer
foreach($movie->getGenres() as $genre){ echo $genre->getName(); }

But I have an error that I cannot resolve
Notice: Trying to access array offset on value of type int in C:\wamp64\www\tmdb_v3-PHP-API--master\controller\classes\data\Genre.php on line 49

Can you help me I just have that to finish my script, thank you in advance

how to get runtime

Hi, i want to know how can i get the movie runtime with the api

And, as an another question... how can a I get a full view of the web? I mean, a php file which gets all the info about a movie

thanks

Auto suggest in search

This is not an issue, but don't know why I can't post in Request.
Have anybody succeeded to implement auto suggestion functionality in search?

Thank you
Chris

Errer Showing

Fatal error: Class 'ApiBaseObject' not found in C:\xampp\htdocs\tmdb\controller\classes\data\Movie.php on line 12

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.