How can I recover data from other sites with php?
Like, I would like to make a streaming site and I wanted the video ratings (or so) to always be updated against imbd.
How can I recover data from other sites with php?
Like, I would like to make a streaming site and I wanted the video ratings (or so) to always be updated against imbd.
Yes, these sites typically create APIs for other sites to get information using Web Services.
I found this API that returns the rating of a series or movie:
Usually return a JavaScript Object Notation (JSON) and in PHP we use the json_encode ($ object) and json_decode ($ json) methods to manipulate JSON.
Example:
Link used:
http://www.omdbapi.com/?t=Game%20of%20Thrones&Season=1&Episode=1
JSON returned:
{"Title": "Winter Is Coming", "Year": "2011", "Rated": "TV-MA", "Released": "17 Apr 2011", "Season" Timothy Van Patten "," Writer ":" David Benioff (created by) "Episode": "1", "Runtime": "62 min" , DB Weiss (created by), George RR Martin ("A Song of Ice and Fire"), David Benioff, DB Weiss "," Actors ":" Sean Bean, Mark Addy, Nikolaj Coster-Waldau, Michelle Fairley "" Plot ":" Jon Arryn, the Hand of the King, is dead. "King Robert Baratheon plans to ask his oldest friend, Eddard Stark, to take Jon's place. nomadic warlord in exchange for an army. "," Language ":" English "," Country ":" USA "," Awards ":" N / A "," Poster ":" "," Metascore ":" N / A "," imdbRating ":" "13098", "imdbID": "tt1480055", "seriesID": "tt0944947", "Type": "episode", "Response": "True"}
PHP:
<?php
/* Retorna um JSON de String a partir do método file_get_contents
e decodifica esta String de JSON a partir do método json_decode para manipular no PHP. */
$json = json_decode(file_get_contents('http://www.omdbapi.com/?t=Game%20of%20Thrones&Season=1&Episode=1'));
?>
Direct access to data from a website that does not have an API or web service is very difficult (and could even be fraud). @Giancarlo mentioned a very good solution, being this access to an API.
Many websites have or give access to data with an API. There are usually directions, tutorials, and documentation on how to access these APIs, and the information they will form.