The Movie Database Support

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;

3 replies (on page 1 of 1)

Jump to last post

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.

try: api_key=' . $apikey

instead of: api_key' . $apikey

ohh, and get a new API key, that one's public now :)

P.S. I just removed the API key from the original post.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login