如何从TMDB API获取更多数据



当我从电影数据库api中获取电影数据时,我只得到一个包含一部电影数据的对象,如何才能获得多部电影的多个对象。

JS代码:

const API_KEY = 'https://api.themoviedb.org/3/movie/550?api_key=955df506af92364cd94a8289d4165e01';
const BASE_URL = 'https://api.themoviedb.org/3';
const API_URL = BASE_URL + '/discover/movie?sort_by=popularity.desc';
fetch(API_KEY).then(response => {
if(!response.ok) {
throw error('error')
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.log('error')
})

任何帮助都将不胜感激,我只想学习如何从api生成更多数据,我对api还很陌生。

这是因为您使用的API_KEY变量包含一个电影链接。你只需要'?对于api_KEY变量为"api=",而获取api_URL。

const API_KEY = '?api_key=955df506af92364cd94a8289d4165e01'; /*API_KEY should only contain the api_key */
const BASE_URL = 'https://api.themoviedb.org/3';
const API_URL = BASE_URL + '/discover/movie?sort_by=popularity.desc' + API_KEY; /*Add the API_KEY here*/
fetch(API_URL).then(response => { /*Call the API_URL not the API_KEY*/
if(!response.ok) {
throw error('error')
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.log('error')
})

最新更新