I am trying to parse messages from a public Facebook fan page wall, but it returns a blank page.
$source = "http://www.facebook.com/?sk=wall&filter=2";
libxml_use_internal_errors(TRUE);
$dom = new DOMDocument();
$dom->loadHTML($source);
$xml = simplexml_import_dom($dom);
libxml_use_internal_errors(FALSE);
$message = $xml->xpath("//span[@class='messageBody']");
return (string)$message[0] . PHP_EOL;
This is not the right way to fetch data from Facebook, and it's clear that you want to avoid creating a Facebook Application.
But the good news is that you can still use the FQL, try the below query in the Graph API Explorer.
In the below query, we queried the
stream
table to get the Facebook Developers page's public feeds:It'll return all the "public" feeds of the page. Obviously you may need retrieve more fields to create a meaningful result.
You need to provide a valid
access_token
to even access public posts. Read more here.The
DOMDocument::loadHTML()
method, which you are using, expects the HTML content as a parameter -- and not an URL.Here, you are trying to interpret your URL as some HTML content -- and not what it links to.
using this method, you might want to try with one that works on a file, or a remonte content, such as
DOMDocument::loadHTMLFile()
.Yet another approach would be to use the JSON from the Graph API