-1

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?

Community
  • 1
  • 1
Kirluu
  • 13
  • 1
  • 6

1 Answers1

1

You can compile your php code using following online php compiler

http://www.tutorialspoint.com/codingground.htm

http://phpfiddle.org/

And for sql

http://sqlfiddle.com/

Santosh Jagtap
  • 995
  • 8
  • 17
  • I have tried both of the PHP options, however I cannot seem to make it work. I have tried placing the code from the post inside the provided php tag and outside of it, but neither appears to work for me. What should I do exactly? – Kirluu Aug 10 '15 at 12:43
  • As my "EDIT" states, phpfiddle works out, but returns a print: "Array()". How might I be able to print each value individually? – Kirluu Aug 10 '15 at 12:53
  • send the phpfiddle link. Code what you did – Santosh Jagtap Aug 10 '15 at 12:54
  • check what you are getting in $fanpage_data. If its empty then your code returning the $ret which empty array....May be this where you getting wrong – Santosh Jagtap Aug 10 '15 at 12:57
  • I posted my current code in the first post in a second edit. – Kirluu Aug 10 '15 at 13:04
  • As I already said you $fanpage_data['id'] is empty and code returning the empty array from there. Check the code thoroughly and debug it. – Santosh Jagtap Aug 10 '15 at 13:07
  • I understand that. I currently am asking about the Facebook API (In case you know of it), and whether it might've changed since the time when the PHP script was written? As it probably has, do you have any clue as to how I might be able to make the same call but in the way that they want it done today, rather than back in 2013? The API call is clearly invalid, which I understand. I am currently trying to find out where I can access the equivalent data in the Facebook API... – Kirluu Aug 10 '15 at 13:21
  • Sorry I don't have any idea about facebook API changes. Please ask different question related to facebook API it will get the attention. I have give the answer to your current question and if you think useful then accept and ask another. – Santosh Jagtap Aug 10 '15 at 13:24