简体   繁体   English

如何从 TMDB API 中提取更多数据?

[英]How do I pull more data from the TMDB API?

When I fetch movie data from the movie database api I only get a single object that contains data for one movie, how can I get multiple objects for multiple movies.当我从电影数据库 api 获取电影数据时,我只得到一个包含一部电影数据的 object,我怎样才能获得多部电影的多个对象。

JS Code: 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')
})

Any help will be appreciated, I just want to learn how to generate more data from the api, im fairly new with api's.任何帮助将不胜感激,我只想了解如何从 api 生成更多数据,我对 api 来说是相当新的。

It is because you are using the API_KEY variable which contains one movie link.这是因为您正在使用包含一个电影链接的 API_KEY 变量。 You only need the '?api=' for the API_KEY variable and fetch the API_URL instead.您只需要 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')
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM