Skip to content

Instantly share code, notes, and snippets.

@J2TEAM
Created May 20, 2017 09:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save J2TEAM/c7987cde2e85effa639c2e7bc4dde12d to your computer and use it in GitHub Desktop.
Save J2TEAM/c7987cde2e85effa639c2e7bc4dde12d to your computer and use it in GitHub Desktop.
<?php /* Developed by Juno_okyo */
define('ACCESS_TOKEN', 'YOUR_ACCESS_TOKEN'); // EDIT HERE
function request($url)
{
if ( ! filter_var($url, FILTER_VALIDATE_URL)) {
return FALSE;
}
$options = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE,
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_ENCODING => '',
CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36',
CURLOPT_AUTOREFERER => TRUE,
CURLOPT_CONNECTTIMEOUT => 15,
CURLOPT_TIMEOUT => 15,
CURLOPT_MAXREDIRS => 5,
CURLOPT_SSL_VERIFYHOST => 2,
CURLOPT_SSL_VERIFYPEER => 0
);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
unset($options);
return $http_code === 200 ? $response : FALSE;
}
function scan($postId) {
$graph = request('https://graph.facebook.com/v2.9/' . $postId . '/comments?fields=message,from{id}&limit=100&access_token=' . ACCESS_TOKEN);
if ($graph !== FALSE) {
$json = json_decode($graph);
$result = [];
if (isset($json->data) && count($json->data) > 0) {
foreach ($json->data as $comment) {
if (strpos($comment->message, '.facebook.com/groups/') !== FALSE && $comment->from->id !== '100001518861027') {
$result[] = $comment->id;
}
}
// Get 3 random comments
for ($i=0; $i < 3; $i++) {
echo $result[array_rand($result)] . '<br>';
}
}
}
}
scan('100003880469096_499340353731423'); // EDIT HERE
@thanhnam18
Copy link

$url, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_HEADER => FALSE, CURLOPT_FOLLOWLOCATION => TRUE, CURLOPT_ENCODING => '', CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36', CURLOPT_AUTOREFERER => TRUE, CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_TIMEOUT => 15, CURLOPT_MAXREDIRS => 5, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => 0 ); $ch = curl_init(); curl_setopt_array($ch, $options); $response = curl_exec($ch); $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); unset($options); return $http_code === 200 ? $response : FALSE; } function scan($postId) { $graph = request('https://graph.facebook.com/v2.9/' . $postId . '/comments?fields=message,from{id}&limit=100&access_token=' . ACCESS_TOKEN); if ($graph !== FALSE) { $json = json_decode($graph); $result = []; if (isset($json->data) && count($json->data) > 0) { foreach ($json->data as $comment) { if (strpos($comment->message, '.facebook.com/groups/') !== FALSE && $comment->from->id !== '100001518861027') { $result[] = $comment->id; } } // Get 3 random comments for ($i=0; $i < 3; $i++) { echo $result[array_rand($result)] . '
'; } } } } scan('100003880469096_499340353731423'); // EDIT HERE

Copy link

ghost commented Aug 16, 2018

Phần random sẽ có thể trùng giá trị

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment