Comments (4)
Your code works. It loads only the Cast not the Crew. When want both try something like this:
$cast = $movie->getCast(); //your code
$crew = $movie->getCrew(); //Not in your code
//Your code
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();;
}
}
}
//Not in your code
foreach ($crew as $person) {
echo '<li>' . $person->getName() . ' </li>';
echo '<img src="' . $tmdb->getImageURL('w185') . $person->getProfile() . '"/></li>';
}
I tried it with deadpool 2 and it renders every crew member and every actor in my case. As i mentioned in my previous comment you have to specify your "append to response"-fields for the tmdb api. That you can do in the default configuration (if you use it).
Let me explain it: If you want to load Data for a specific person the library internal calls the following url:
https://api.themoviedb.org/3/person/{person_id}?api_key=<<api_key>>&language=en-US
But you are able to make something like this:
https://api.themoviedb.org/3/person/{person_id}?api_key=<<api_key>>&language=en-US&append_to_response=movie_credits
This tells the API that you additionally want to get the movie_credits field for the person response.
In this library you dont have to manipulate the URL directly. You only define the additional fields in your configuration file:
`configuration/default.php``
(Look at my comment above)
Further Information here: https://developers.themoviedb.org/3/getting-started/append-to-response
from tmdb_v3-php-api-.
Hey @omar-mohamed23
Is it really a use case to get the cast and the crew in one function call? You can make two calls and you have your required data.
But yeah it is possible. But a little bit harder:
Every Object extending the ApiBaseObject has a general get() function. You can make something like this:
$movie->get('credits');
But attention: When you use the get() call you receive the API Response. Not Model Instances. You have to create Person instances manually with the correct data.
For your mentioned error with your code:
Make sure your settings are correct. It seems that you are requesting a Ressource from the API and not specified the appended field (like movie_credits).
Look in this file in your project: configuration/default.php
Look at my file:
// Data Return Configuration - Manipulate if you want to tune your results
$cnf['appender']['movie'] = array('trailers', 'images', 'credits', 'translations', 'reviews');
$cnf['appender']['tvshow'] = array('trailers', 'images', 'credits', 'translations', 'keywords');
$cnf['appender']['person'] = array('movie_credits', 'tv_credits', 'images');
Please look at the TMDB API Documentation. You are able to specify "extra fields" (like "movie_credits" for Persons). This extra fields are not send in the API Response by default. You have to manually specify them. If you want to call getMovieRoles()
on a Person Instance make sure you have added "movie_credits" to the additional fields.
from tmdb_v3-php-api-.
First thing Thanks for your fast reply :)
can you please give me an example on my code how to specify the appended field ? I checked the settings and they are the default. What confuse me that in this example I used on Deadpool 2 the result is what I need but it only show me the first 40 characters when I checked the original array from TMDB I think it stop showing character for the crew array in the API "Starting from (Sala Baker) in this example" that's what made me think to merge both cast and crew so I can loop through the array and get each character name for every Person.
from tmdb_v3-php-api-.
@bogdanfinn Really Thank you for your help
I get the error on my test VPS when I try the code but on my localhost XAMPP server it works fine. I think it might be an error with my PHP setup on my VPS.
Thanks again for your help :)
from tmdb_v3-php-api-.
Related Issues (20)
- How to get Movie/TV/Person search page ? HOT 2
- No ../tmdb-api.php file included, on this code HOT 1
- Errer Showing HOT 16
- List of film genres HOT 11
- Empty youtube video problem HOT 5
- how to show movie certification HOT 3
- setAPIKey not working
- Trailer in TV Show HOT 3
- Num of episodes in seasons loop HOT 3
- episodes images not working HOT 1
- I cant get the backdrop HOT 1
- getImageURL not working
- Get Production (Aired) Year for TV Show
- How do I get the [character] each actor played in the movie??
- Auto suggest in search
- A missed quote in README.markdown
- imdb tv id get data not working
- this genre data
- Error Handler
- please insert RatedMovies
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tmdb_v3-php-api-.