I am trying to link a system of publications that I have with the Facebook API, to give my users the option to publish their articles on social networks automatically. The question is: Am I a member of several groups, (only admin 2), Can I publish content in groups in which I do not administer (being a member), or is it only possible to publish in the groups I manage? ..
The second I have already solved (I can already publish in the groups I manage), my code is something like this:
public function publicar($titulo, $url){
$e= new configuracionController();
$userid=$e->getFbUserId();
$accessToken = $empresa->getFBToken();
$datos = array(
'message'=> $titulo,
'link' => $url
);
try {
$requestGroups = $this->fb->get('/me/groups', $accessToken);
$groups = $requestGroups->getGraphEdge()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
foreach ($groups as $key) {
try {
$requestMultiPost = $this->fb->post('/' . $key['id'] . '/feed', $datos, $accessToken);
$multiPost = $requestMultiPost->getGraphNode()->asArray();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
}
print_r($multiPost);
}