I'm trying to set up a script that will scrape my facebook pages and return to me all the info so I will be able to insert it to the database (Name, Likes etc..). I built a CURL script but its not working for some weird reason. It throws me "Notice: Trying to get property of non-object in C:\xampp\XXX\curltest.php on line 26".
Yes JSON and CURL are enabled on my server. I will be glad if someone will help. ;)
<?php
// create both cURL resources
$ch1 = curl_init();
$ch2 = curl_init();
// set URL and other appropriate options
curl_setopt($ch1, CURLOPT_URL, "http://graph.facebook.com/19292868552");
curl_setopt($ch1, CURLOPT_HEADER, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch2, CURLOPT_URL, "http://graph.facebook.com/youtube");
curl_setopt($ch2, CURLOPT_HEADER, 0);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
//create the multiple cURL handle
$mh = curl_multi_init();
//add the two handles
curl_multi_add_handle($mh,$ch1);
curl_multi_add_handle($mh,$ch2);
$running=null;
//execute the handles
do {
usleep(10000);
$Likes = json_decode(curl_multi_exec($mh,$running));
return $Likes->data;
//output the message body
echo($Likes->likes);
//add a line break to separate comments
echo("<br />");
} while ($running > 0);
//close the handles
curl_multi_remove_handle($mh, $ch1);
curl_multi_remove_handle($mh, $ch2);
curl_multi_close($mh);
?>
Also I would like to know how to to make some kind of "while" function. If, let's say, I would like to scrape 10 URLs I can't write them one-by-one so I would be better off making an SQL query to pull those URLs from there.
Thanks in advance.