I have the same problem as in this older post: Facebook API: Get fans of / people who like a page
My question regards the code provided by the top answer:
See further below for updated code
I would like to know how I can somehow run this code (With my own parameters, of course). I have looked at some options for online PHP Script executors, since I am not familiar with any IDE's or likewise that are available. More essentially: I do not know any way in which I can get to run this PHP script (Assuming it is valid and not missing some vital setup around it).
I'm hoping that there's some sort of console available, where I can then get to see the resulting array printed fully by the end of the execution.
What are my (easiest) options? I'm not looking to fully learn PHP from the bottom. I'm just looking for the functionality described in the post I linked to.
Thanks a lot in advance to anyone who can provide the necessary insight! :)
Best regards, Kirluu
EDIT:
http://phpfiddle.org/ seems to do what I was looking for, but the output is simply "Array()". I'd like to print all of its values - how might I achieve this? I attempted to change the execution line to:
print_r(array_values(fetch_fb_fans('ComputerHjælp', 5, 400000)));
This doesn't change the result though.
EDIT2: I made some edits and enclosed the code in the php tag as prescribed by the phpfiddle website. I now simply do not get any data it appears, as the "nope" is now printed instead of array values. Is something wrong with the coders access of the Facebook API?
<?php
function fetch_fb_fans($fanpage_name, $no_of_retries = 10, $pause = 500000 /* 500ms */){
$ret = array();
// get page info from graph
$fanpage_data = json_decode(file_get_contents('http://graph.facebook.com/' . $fanpage_name), true);
if(empty($fanpage_data['id'])){
// invalid fanpage name
return $ret;
}
$matches = array();
$url = 'http://www.facebook.com/plugins/fan.php?connections=100&id=' . $fanpage_data['id'];
$context = stream_context_create(array('http' => array('header' => 'User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0')));
for($a = 0; $a < $no_of_retries; $a++){
$like_html = file_get_contents($url, false, $context);
preg_match_all('{href="https?://www\.facebook\.com/([a-zA-Z0-9._-]+)" data-jsid="anchor" target="_blank"}', $like_html, $matches);
if(empty($matches[1])){
// failed to fetch any fans - convert returning array, cause it might be not empty
return array_keys($ret);
}else{
// merge profiles as array keys so they will stay unique
$ret = array_merge($ret, array_flip($matches[1]));
}
// don't get banned as flooder
usleep($pause);
}
return array_keys($ret);
}
$val = fetch_fb_fans('Komplett.dk', 5, 400000);
if(empty($val)){
echo "nope";
}
foreach($val as $key => $value)
{
echo $key." has the value". $value;
}
?>
Thing is here, that I know for a fact that there is a Facebook site called "Komplett.dk", however clearly something is not working. The code is from April 2013. Has the Facebook API been updated in some way, which does not allow this code to work as intended?