0

have an API returning a body of data. Just want to pull the 'steaming info' section

get request is


$curl = curl_init();

curl_setopt_array($curl, [
    CURLOPT_URL => "https://streaming-availability.p.rapidapi.com/get/basic?country=gb&imdb_id=tt0413300&output_language=en",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "GET",
    CURLOPT_HTTPHEADER => [
        "x-rapidapi-host: streaming-availability.p.rapidapi.com",
        "x-rapidapi-key:xxxxxx"
    ],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}

output is

{"imdbID":"tt0413300","tmdbID":"559","imdbRating":62,"imdbVoteCount":551305,"tmdbRating":63,"backdropPath":"/6MQmtWk4cFwSDyNvIgoJRBIHUT3.jpg","backdropURLs":{"1280":"https://image.tmdb.org/t/p/w1280/6MQmtWk4cFwSDyNvIgoJRBIHUT3.jpg","300":"https://image.tmdb.org/t/p/w300/6MQmtWk4cFwSDyNvIgoJRBIHUT3.jpg","780":"https://image.tmdb.org/t/p/w780/6MQmtWk4cFwSDyNvIgoJRBIHUT3.jpg","original":"https://image.tmdb.org/t/p/original/6MQmtWk4cFwSDyNvIgoJRBIHUT3.jpg"},"originalTitle":"Spider-Man 3","genres":[28,12,878],"countries":["US"],"year":2007,"runtime":139,"cast":["Tobey Maguire","Kirsten Dunst","James Franco","Thomas Haden Church","Topher Grace","Bryce Dallas Howard","Dylan Baker"],"significants":["Sam Raimi"],"title":"Spider-Man 3","overview":"The seemingly invincible Spider-Man goes up against an all-new crop of villains—including the shape-shifting Sandman. While Spider-Man’s superpowers are altered by an alien organism, his alter ego, Peter Parker, deals with nemesis Eddie Brock and also gets caught up in a love triangle.","tagline":"The battle within.","video":"wPosLpgMtTY","posterPath":"/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","posterURLs":{"154":"https://image.tmdb.org/t/p/w154/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","185":"https://image.tmdb.org/t/p/w185/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","342":"https://image.tmdb.org/t/p/w342/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","500":"https://image.tmdb.org/t/p/w500/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","780":"https://image.tmdb.org/t/p/w780/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","92":"https://image.tmdb.org/t/p/w92/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg","original":"https://image.tmdb.org/t/p/original/2jLxKF73SAPkyhIWrnv67IH7kJ1.jpg"},"age":10,"streamingInfo":{"netflix":{"gb":{"link":"https://www.netflix.com/title/70047101/","added":1635749849,"leaving":0}}},"originalLanguage":"en"}

what do I need to change in the php to just show the streaming link "https://www.netflix.com/title/70047101/

Jonny
  • 1
  • Decode it to an object, and then read the property. – ADyson Jan 05 '22 at 16:35
  • thanks how would i do that – Jonny Jan 05 '22 at 16:57
  • By using json_decode(), and then treating it like any other PHP object/array whose contents you want to access. Read the link in the blue box above your question - the reason that's there is because it already contains the answer to your question. – ADyson Jan 05 '22 at 16:58

0 Answers0