通过烂番茄检索电影 API

Retrieving Movies Via Rotten Tomatoes API

我想知道如何使用 JavaScript/JQuery 从烂番茄 Api 检索电影。我查看了文档并查看了示例,但我仍然不明智,因为 API 对我来说是新的。如果有人能给我一个下面的例子,那就太好了:

http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?apikey=[your_api_key]&limit=1

(我知道我需要输入我的 api 密钥才能运行)

谢谢

根据网站上的示例 API,我为您的目的创建了此示例代码 - 获取票房收入最高的电影。 limit=1 只会 return 排序列表中的第一部电影。

要查看包含您可以检索的所有 JSON key/value 的整个 XML,请使用 this link

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

    <script>
        var apikey = "YourApiKeyHERE";
        var baseUrl = "http://api.rottentomatoes.com/api/public/v1.0";

        // construct the uri with apikey
        var moviesSearchUrl = baseUrl + '/lists/movies/box_office.json?apikey=' + apikey + '&limit=1';

        $(document).ready(function() {

            // send off the query
            $.ajax({
            url: moviesSearchUrl,
            dataType: "jsonp",
            success: searchCallback
            });
        });

        // callback for when we get back the results
        function searchCallback(data) {
            $(document.body).append('Found ' + data.total + ' results for Top Box Office Earning Movie');
            var movies = data.movies;
            $.each(movies, function(index, movie) {
            $(document.body).append('<h1>' + movie.title + '</h1>');
            $(document.body).append('<img src="' + movie.posters.thumbnail + '" />');
            });
        }

    </script>

</head>
<body>
</body>
</html>