gpt4 book ai didi

javascript - 无法访问 JSON 数据并出现错误 404(TMDB)?

转载 作者:行者123 更新时间:2023-11-29 19:03:58 25 4
gpt4 key购买 nike

我想要 TMDB 中所需电影的海报。我无法从 TMDB API 获取 JSON 数据。我已发送请求,但收到错误 404“找不到您请求的资源”。访问 TMDB 电影 API 的链接:https://developers.themoviedb.org/3/movies/get-movie-images这是我的代码:

<script type="text/javascript">
var film = "speed";
var api_key = 'my-api-key';
var requestURL = "https://api.themoviedb.org/3/movie/images?api_key=" + api_key +"&language=en-US&callback=?";

var request = new XMLHttpRequest();

request.open('GET', requestURL);

request.responseType = 'json';

request.send();

request.onload = function(){
var myjsondata = request.response; //request.response contains all our JSON data

console.log(myjsondata);
}
</script>

我的控制台中的 JSON 数据应该如下所示: enter image description here

但是我在我的控制台中得到了这个:错误 404 找不到这个资源。

最佳答案

您需要在请求 URL 的路径部分包含一个 movie_id 值,对吗?像这样:

var requestURL = "https://api.themoviedb.org/3/movie/"
+ movie_id + "/images?api_key=" + api_key +"&language=en-US&callback=?";

至少in the documentation cited in the question这就是显示的内容:

GET /movie/{movie_id}/images

Path Parameters

movie_id : integer

Example:

https://api.themoviedb.org/3/movie/{movie_id}/images?api_key=<<api_key>>

例如,要获取 ID 为 9340 的电影图像的 JSON 格式数据:

https://api.themoviedb.org/3/movie/9340/images?api_key=<<api_key>>

您可以通过使用 curl 或其他方式进行测试来确认它是否有效:

$ curl "https://api.themoviedb.org/3/movie/9340/images?api_key=<<api_key>>"

{
"backdrops": [
{
"aspect_ratio": 1.777251184834123,
"file_path": "/qKeyO9gXaaK0g87tvvqOPK1siwc.jpg",
"height": 1688,
"iso_639_1": null,
"vote_average": 5.454545454545455,
"vote_count": 3,
"width": 3000
},

关于javascript - 无法访问 JSON 数据并出现错误 404(TMDB)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44406113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com