I'm new to JSON API and i was just testing it out to understand how this works so this is an javascript example of json
$(document).ready(function() {
var url = 'https://api.themoviedb.org/3/movie/',
mode = 'search/',
input,
movieName,
key = '?api_key=e9dfeccf734a61b9a52d9d7660f0d0a1';
$('button').click(function() {
var input = $('#movie').val(),
movieName = encodeURI(input);
$.ajax({
url: url + mode + movieName + key,
dataType: 'jsonp',
success: function(data) {
console.log(data);
}
});
});
});
And HTML
<input id="movie" type="text" /><button>Search</button>
I'm trying to use that API using PHP but failed..
<?php
$json = file_get_contents("url");
$obj = json_decode($json);
$response = array();
$json_response = json_encode($response);
echo $json_response;
header("Content-type: application/json");
?>
Anyone can help me with using search query as a name of movie to fetch out the details..
Example: https://api.themoviedb.org/3/movie/297762?api_key=e9dfeccf734a61b9a52d9d7660f0d0a1&language=en-US
I made this work but i need to style it..
<?php
//$url = file_get_contents('https://api.themoviedb.org/3/movie/297762?api_key=e9dfeccf734a61b9a52d9d7660f0d0a1&language=en-US');
//echo $url;
$json_url = "https://api.themoviedb.org/3/movie/297762?api_key=e9dfeccf734a61b9a52d9d7660f0d0a1&language=en-US";
$json = file_get_contents($json_url);
$data = json_decode($json, TRUE);
echo "<pre>";
print_r($data);
echo "</pre>";
?>