Skip to content

Instantly share code, notes, and snippets.

@Korko
Last active December 16, 2015 04:29
Show Gist options
  • Save Korko/5377865 to your computer and use it in GitHub Desktop.
Save Korko/5377865 to your computer and use it in GitHub Desktop.
Simple tool to select a random facebook user who likes a story
<?php
if(!isset($_GET['stories'])) {
die('USAGE : randomLikes.php?stories=&lt;story id,story id...&gt;');
}
$stories = explode(',', $_GET['stories']);
$alldata = array();
foreach($stories as $story) {
$url = 'https://graph.facebook.com/'.intval($story).'/likes?limit=0';
$alldata += json_decode(file_get_contents($url), true))['data'];
}
$rand = $alldata[array_rand($alldata)];
$calldata = count($alldata);
$listalldata = '';
foreach($alldata as $data) {
$listalldata .= '<li><a href="http://www.facebook.com/'.$data['id'].'">'.$data['name'].'</a></li>';
}
echo <<<EOT
<html>
<head>
<title>Random Likes</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p>The winner is : <a href="http://www.facebook.com/{$rand['id']}">{$rand['name']}</a></p>
<p>
There was {$calldata} participants for story <a href="http://www.facebook.com/{$_GET['story']}">{$_GET['story']}</a> :
<ul>{$listalldata}</ul>
</p>
</body>
</html>
EOT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment