PHP code example of tiagosampaio / tmdb-api-php

1. Go to this page and download the library: Download tiagosampaio/tmdb-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiagosampaio / tmdb-api-php example snippets




$token  = new \Tmdb\ApiToken('your_tmdb_api_key_here');
$client = new \Tmdb\Client($token);

$client = new \Tmdb\Client($token, ['secure' => false]);

$client = new \Tmdb\Client($token, [
    'cache' => [
        'path' => '/tmp/php-tmdb'
    ]
]);

use Doctrine\Common\Cache\ArrayCache;

$client = new \Tmdb\Client($token, [
        'cache' => [
            'handler' => new ArrayCache()
        ]
    ]
);

$client = new \Tmdb\Client($token, [
    'cache' => [
        'enabled' => false
    ]
]);

$client = new \Tmdb\Client($token, [
    'log' => [
        'enabled' => true,
        'path'    => '/var/www/php-tmdb-api.log'
    ]
]);

$client = new \Tmdb\Client($token, [
    'log' => [
        'enabled' => true,
        'handler' => new \Monolog\Handler\ChromePHPHandler()
    ]
]);

$movie = $client->getMoviesApi()->getMovie(550);

$movie = $client->getMoviesApi()->getMovie(550, array('language' => 'en'));

$repository = new \Tmdb\Repository\MovieRepository($client);
$movie      = $repository->load(87421);

echo $movie->getTitle();

$repository = new \Tmdb\Repository\MovieRepository($client);
$topRated = $repository->getTopRated(array('page' => 3));
// or
$popular = $repository->getPopular();

$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
$config = $configRepository->load();

$imageHelper = new \Tmdb\Helper\ImageHelper($config);

echo $imageHelper->getHtml($image, 'w154', 154, 80);

$plugin = new \Tmdb\HttpClient\Plugin\LanguageFilterPlugin('nl');

$plugin = new \Tmdb\HttpClient\Plugin\AdultFilterPlugin(true);

foreach($movie->getImages()->filter(
        function($key, $value){
            if ($value instanceof \Tmdb\Model\Image\PosterImage) { return true; }
        }
    ) as $image) {

    // do something with all poster images
}

$backdrop = $movie
    ->getImages()
    ->filterBackdrops()
;
json
"php-tmdb/api": "~2.1"