Skip to content

Instantly share code, notes, and snippets.

@mdwitr0
Created May 12, 2023 20:39
Show Gist options
  • Save mdwitr0/9fe0ce6163bd796a623096efb630e1f6 to your computer and use it in GitHub Desktop.
Save mdwitr0/9fe0ce6163bd796a623096efb630e1f6 to your computer and use it in GitHub Desktop.
<?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