+ 2

How to get genre ids with genre names in TMDb api?

I'm having issues with showing genres names for each movie displayed.I want each genre_ids from movies api give me names of genres but I am getting only ids which are 0,18 etc and how to convert it into action, adventure. Please help me to solve this in javascript.

6th Aug 2021, 4:58 AM
Arun Jamson
Arun Jamson - avatar
17 Answers
9th Aug 2021, 7:05 AM
Calviղ
Calviղ - avatar
+ 3
Arun Jamson I went to register one api key, it is actually works. Please check https://code.sololearn.com/WZQYiojdrjxhB6FKJ/?ref=app
7th Aug 2021, 8:51 AM
Calviղ
Calviղ - avatar
+ 2
Try this const apiKey = 'your api key'; const movieId = 100; /** * Fetch movie data from themoviedb.org * @param {number} id Movie id * @return {object} Movie object */ async function fetchMovie(id) { const response = await fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=${apiKey}`); const movie = await response.json(); return movie; } fetchMovie(movieId).then(movie => { movie.genres.forEach(genre => { console.log("genre id: " + genre.id + ", genre name: " + genre.name); // output genre and id }) }); https://code.sololearn.com/WhD17FVXyeVE/?ref=app
6th Aug 2021, 2:45 PM
Calviղ
Calviղ - avatar
+ 2
https://code.sololearn.com/WOzGctmT7QB8/?ref=app
8th Aug 2021, 9:24 AM
Calviղ
Calviղ - avatar
+ 1
In my code it is showing foreach is not defined error
6th Aug 2021, 5:02 PM
Arun Jamson
Arun Jamson - avatar
+ 1
Arun Jamson you need to set a valid api key for the code to work.
7th Aug 2021, 4:18 AM
Calviղ
Calviղ - avatar
+ 1
Arun Jamson Then you have an invalid key, try to request again.
7th Aug 2021, 4:25 AM
Calviղ
Calviղ - avatar
0
Well if you are at front end maybe get tag by id?
6th Aug 2021, 5:22 AM
Abs Sh
Abs Sh - avatar
0
But if u are at backend it depends on library and stuff
6th Aug 2021, 5:23 AM
Abs Sh
Abs Sh - avatar
0
I am not asking about tags but in api that arrays name is genre_id, please read question properly bro.
6th Aug 2021, 12:58 PM
Arun Jamson
Arun Jamson - avatar
0
Calvin bro i didn't get it and in your playground it is showing movies undefined can you explain by showing in codeplayground please.
6th Aug 2021, 4:54 PM
Arun Jamson
Arun Jamson - avatar
0
I have put then also it is showing genres not defined
7th Aug 2021, 4:20 AM
Arun Jamson
Arun Jamson - avatar
0
Ok
7th Aug 2021, 9:11 AM
Arun Jamson
Arun Jamson - avatar
7th Aug 2021, 4:58 PM
Arun Jamson
Arun Jamson - avatar
0
And how to get random movies genre in above code please bro help me.
8th Aug 2021, 6:57 AM
Arun Jamson
Arun Jamson - avatar
0
Bro but the genre ids are in numbers how to get in strings like action or comedy of same movie
8th Aug 2021, 10:58 AM
Arun Jamson
Arun Jamson - avatar
0
Thanks bro
9th Aug 2021, 7:08 AM
Arun Jamson
Arun Jamson - avatar
OSZAR »