Rotten Tomatoes API Forums

General

RSS Feed

PHP code keeps returning "error parsing json."

  1. From http://developer.rottentomatoes.com/docs/read/json/v10/examples ODH writes:

    Only the Javascript example code worked for me. The PHP code keeps returning "error parsing json." I'm positive that I inserted the api key correctly. Quite strange...

    Steve N replies:

    Hi ODH, I just tweaked the example a bit: the endpoint url it was hitting was 'movies' and I changed it to include the extension as well, so it is now 'movies.json'. Give that a try and let us know if it doesn't work.

    ODH says:

    I tried a bunch of combinations of endpoint urls. None of them seem to work (including your updated version). Let me know if you have other ideas. Thank you!

    Do you think it's possible that my PHP settings are the problem?

    Message edited by Steve N. 3 months ago

  2. Steve N.2 years ago

    Hi ODH, Here are some things to try/debug this

    • does your server provide curl?
    • can you use curl to hit other sites?
    • what is the output before the json decode

    One way to check for curl is to make a php file with the following contents:

    1. <?php
    2. phpinfo();
    3. ?>

    Open that file up in a browser and search for curl. There should be a section heading for curl and a line with "cURL support: enabled".

    Before calling json_decode($data), just echo out the data to see what we get.

    1. echo $data

    Once we see what the output of that is, we can if we're actually getting data out of the curl call and debug from there.

  3. ODH2 years ago

    Nothing's getting returned. I tried to echo out $data and got nothing. Also, FYI, if ($data==null) comes back as true.

    cURL support is enabled.

  4. pmuessig2 years ago

    I've been working with the api flawlessly until i sat down tonight to do some recreational programming on my movie webapp and ran into this "error parsing json." issue.

    After looking at my code and then back to the example, it seems that the json path was changed from http://api.rottentomatoes.com/api/public/v1.0/movies to http://api.rottentomatoes.com/api/public/v1.0/movies.json

    As far as 6months ago the first path would return the data fine. I guess that endpoint is no longer valid.

  5. PaparazzoKid17 months ago

    Using the example code in the docs, I am getting error:

    Invalid argument supplied for foreach()...

    I tried wrapping the foreach function with:

    if (is_array($movies)) { foreach ($movies as $movie) { echo '<li><a href="' . $movie->links->alternate . '">' . $movie->title . " (" . $movie->year . ")</a></li>"; } }

    but now hides the error, so $movies is not an array.

    I have literally just signed up for an API key and was hoping I could get stuck straight but can't.

    Any help on this would be great.

  6. Donny Estee5 months ago

    Guys, I think this code here is much shorter and easier, it requires no additional PHP extensions:

    <?php $apikey = 'your api code here'; $q = urlencode('Toy Story'); // make sure to url encode an query parameters

    // construct the query with our apikey and the query we want to make $jsonurl = 'http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=' . $apikey . '&q=' . $q;

    $json = file_get_contents($jsonurl,0,null,null); $json_output = json_decode($json); if ($json_output === NULL) die('Error parsing json');

    // play with the data! $movies = $json_output->movies; echo '<ul>'; foreach ($movies as $movie) { echo '<li><a href="' . $movie->links->alternate . '">' . $movie->title . " (" . $movie->year . ")</a></li>"; } echo '</ul>';

    ?>

  7. Shubhang Verma3 months ago

    The example code given for PHP always says ' Error parsing json ' but i am sure that i have entered the correct key.

[ Page 1 of 1 ]