1. Go to this page and download the library: Download chiiya/tmdb-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/ */
chiiya / tmdb-php example snippets
use Chiiya\Tmdb\Http\Client;
use Chiiya\Tmdb\Repositories\MovieRepository;
// Create an authenticated client
$client = Client::createAuthenticatedClient('your_v4_bearer_token');
// Create a repository
$repository = new MovieRepository($client);
// Get movie details
$movie = $repository->getMovie(550);
echo $movie->title; // "Fight Club"
echo $movie->overview; // Movie description
echo $movie->release_date->format('Y-m-d'); // "1999-10-15"
use Chiiya\Tmdb\Query\Language;
use Chiiya\Tmdb\Query\Page;
use Chiiya\Tmdb\Query\IncludeAdult;
use Chiiya\Tmdb\Query\Region;
use Chiiya\Tmdb\Query\Year;
use Chiiya\Tmdb\Query\PrimaryReleaseYear;
use Chiiya\Tmdb\Query\FirstAirDateYear;
use Chiiya\Tmdb\Query\StartDate;
use Chiiya\Tmdb\Query\EndDate;
use Chiiya\Tmdb\Query\ExternalSource;
use Chiiya\Tmdb\Query\AppendToResponse;
// Language parameter
$language = new Language('en-US');
// Pagination
$page = new Page(1);
// Include adult content
$:CREDITS,
AppendToResponse::WATCH_PROVIDERS,
]);
// Get movie with additional data
$movie = $repository->getMovie(550, [
new Language('en-US'),
new AppendToResponse([
AppendToResponse::IMAGES,
AppendToResponse::CREDITS,
AppendToResponse::WATCH_PROVIDERS,
]),
]);
// Search with parameters
$movies = $repository->searchMovies('action', [
new Language('en-US'),
new Page(1),
new IncludeAdult(false),
new Year(2023),
]);
$movie = $repository->getMovie(550, [
new AppendToResponse([AppendToResponse::WATCH_PROVIDERS]),
]);
// Access by country code
if (isset($movie->watch_providers['US'])) {
$providers = $movie->watch_providers['US'];
}
$imageBaseUrl = 'https://image.tmdb.org/t/p/';
$size = 'w500'; // or 'original', 'w780', etc.
$fullUrl = $imageBaseUrl . $size . $movie->poster_path;
$movies = $repository->getPopular([new Page(1)]);
echo $movies->page; // Current page
echo $movies->total_pages; // Total pages
echo $movies->total_results; // Total results
// Access results
foreach ($movies->results as $movie) {
echo $movie->title;
}
// Does the response have more pages?
$movies->hasMorePages(); // Returns true if there are more pages
// Get next page
$movies->getNextPageNumber();
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.