it seems like the Json Dataset $data is retrieved, however, it cannot be parsed correctly. Can someone help?
Thanks in advance!
if (extension_loaded('curl'))
{
$headers = array(
'Accept: application/json',
);
$apikey = '###';
$query = ('Iron+Man+1');
$url = 'https://api.themoviedb.org/3/search/movie?api_key' . $apikey . '&query=' . $query;
$session = curl_init();
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
curl_setopt($session, CURLOPT_URL,$url);
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_HEADER, 1);
$data = curl_exec($session);
if ($data === NULL) die ('result sets are empty');
$header_size = curl_getinfo($session, CURLINFO_HEADER_SIZE);
$header = substr($data, 0, $header_size);
$body = substr($data, $header_size);
$error_number = curl_errno($session);
$error_message = curl_error($session);
curl_close($session);
}
else
{
throw new TMDbException('CURL-extension not loaded');
}
$results = json_decode($body, true);
if ($results === NULL) die('Error parsing json');
$moviesRelease = $results➞release_date;
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by Travis Bell
on January 4, 2014 at 10:25 AM
Hi vanessaLing,
First, this is PHP right? It might be helpful to add PHP to the subject line for any PHP developers out there.
Second, have you taken a look at any of the PHP libraries for some ideas as to how they do it? I'm not a PHP dev so I am afraid I am not much help.
Reply by Karl Dietz
on January 5, 2014 at 4:07 PM
try:
api_key=' . $apikey
instead of:
api_key' . $apikey
ohh, and get a new API key, that one's public now :)
Reply by Travis Bell
on January 5, 2014 at 5:59 PM
P.S. I just removed the API key from the original post.