php - Is it possible to extract all names of a facebook group and some basics details about who added them? -
i admin of private facebook group use business, extract names group , date , person added them. i'm interested know there possible way ? ideas or suggestions ?
about extraction format, doesn't matter...
you can extract members names, members id, group description, member role. first generate login url using facebook-php-sdk-v4-5.0-dev:
$fb = new facebook\facebook([ 'app_id' => app_id, 'app_secret' => app_secret, 'default_graph_version' => 'v2.4', // or use v2.5 latest version ]); $helper = $fb->getredirectloginhelper(); $permissions = ['user_managed_groups']; $redirecturl = 'http://localhost/fbapp.php'; $loginurl = $helper->getloginurl($redirecturl, $permissions); echo '<a href="' . $loginurl . '">log in facebook!</a>';
after generating login url implement code response handling , getting required data.
$helper = $fb->getredirectloginhelper(); try { $accesstoken = $helper->getaccesstoken(); setcookie('accesstoken',$accesstoken); } catch(facebook\exceptions\facebookresponseexception $e) { // when graph returns error echo 'graph returned error: ' . $e->getmessage(); exit; } catch(facebook\exceptions\facebooksdkexception $e) { // when validation fails or other local issues echo 'facebook sdk returned error: ' . $e->getmessage(); exit; } $fb->setdefaultaccesstoken($accesstoken); // user groups detail $requestusermanagedgroups = $fb->request('get', '/me/groups?fields=members,from'); //make batch request $batch = ['user-groups' => $requestuserlikes]; try { $responses = $fb->sendbatchrequest($batch); } catch(facebook\exceptions\facebookresponseexception $e) { // when graph returns error echo 'graph returned error: ' . $e->getmessage(); exit; } catch(facebook\exceptions\facebooksdkexception $e) { // when validation fails or other local issues echo 'facebook sdk returned error: ' . $e->getmessage(); exit; }
for better view can use this:
foreach ($responses $key => $response) { if ($response->iserror()) { $e = $response->getthrownexception(); echo '<p>error! facebook sdk said: ' . $e->getmessage() . "\n\n"; echo '<p>graph said: ' . "\n\n"; var_dump($e->getresponse()); } else { echo "<p>(" . $key . ") http status code: " . $response->gethttpstatuscode() . "<br />\n"; echo "response: " . $response->getbody() . "</p>\n\n"; echo "<hr />\n\n"; } }
for group related more better understanding -visit https://developers.facebook.com/docs/graph-api/reference/v2.5/group
and group members related information visit: https://developers.facebook.com/docs/graph-api/reference/v2.5/group/members
Comments
Post a Comment