Created
May 12, 2023 20:39
-
-
Save mdwitr0/9fe0ce6163bd796a623096efb630e1f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function get_movies_by_genres($genres, $page = 1, $limit = 1) { | |
$url = 'https://api.kinopoisk.dev/v1/movie'; | |
$headers = ["X-API-KEY: Your token ..."]; | |
$params = [ | |
'genre.name' => implode(",", $genres), | |
'limit' => $limit, | |
'page' => $page, | |
]; | |
$options = array( | |
'http' => array( | |
'header' => $headers, | |
'method' => 'GET', | |
'content' => http_build_query($params), | |
), | |
); | |
$context = stream_context_create($options); | |
$response = file_get_contents($url, false, $context); | |
$movies = json_decode($response, true); | |
return $movies["docs"]; | |
} | |
$genres = ["триллер", "ужасы"]; | |
$movies = get_movies_by_genres($genres); | |
print_r($movies); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment