Reputation: 85
I had the idea to write a little program which would check every like of a person's Facebook friends. There are presumably other apps that do this, to find your "Perfect Match' and that kind of baloney.
I can find a list of the authorized user's friends, and I can in turn find a list of each friend's interest. I find a friend's likes by accessing the Facebook API, and move on to the next friend.
The problem is that for a person with 1,000 friends, I am accessing the API 1000 seperate time, and I'm not sure if there's a way around this. It's of course, way too slow. Here's my (fairly simple) code so far:
if(isset($_POST['array'])){
//get the posted friends list
$jsonarray = $_POST['array'];
//decode from json
$friendlist = json_decode($jsonarray, true);
//create variable
$count = 0;
//for each friend
foreach ($friendlist as $friend) {
//access their list of likes
$url = file_get_contents("https://graph.facebook.com/" . $friend['id'] . "/likes?limit=1000&access_token=TOKENHERE");
$likes = json_decode($url,true);
foreach($likes['data'] as $like) {
$count++;
}
}
//spit this out, ready for script.js to receive
echo json_encode($count);
} else {
//spit this out, ready for script.js to receive, still needs to be ajax, that's what script.js is expecting
echo json_encode("no data");
}
Thanks in advance for any help you might be able to offer.
Upvotes: 0
Views: 75
Reputation: 31479
You can do this with one FQL query:
select uid, page_id from page_fan where uid in (select uid2 from friend where uid1 = me())
You can execute this via the
/fql?q=...
endpoint.
Upvotes: 1