I am an administrator (manager role) of a Facebook Group. I created an app, and stored its id and secret.
I want my app to be able to post something on the Facebook group's feed. But when I attempt to post, I get the error 190 Invalid OAuth access token signature, even though I able to successfully obtain the access_token with publish_stream and offline_access scopes. It has the form of NNNNNNNNNNNNNNN|XXXXXXXXXXXXXXXXXXXXXXXXXXX, where N is a number (15) and X is a letter or a number (27).
What should I do more to get this accomplished? Here is the code I am using:
public static function postToFB($message, $image, $link) {
//Get App Token
$token = self::getFacebookToken();
// Create FB Object Instance
$facebook = new Facebook(array(
'appId' => self::fb_appid,
'secret' => self::fb_secret,
'cookie' => true
));
//$token = $facebook->getAccessToken();
//Try to Publish on wall or catch the Facebook exception
try {
$attachment = array('access_token' => $token,
'message' => $message,
'picture' => $image,
'link' => $link,
//'name' => '',
//'caption' => '',
'description' => 'More...',
//'actions' => array(array('name' => 'Action Text', 'link' => 'http://apps.facebook.com/xxxxxx/'))
);
$result = $facebook->api('/'.self::fb_groupid.'/feed/', 'post', $attachment);
} catch (FacebookApiException $e) { //If the post is not published, print error details
echo '<pre>';
print_r($e);
echo '</pre>';
}
}
Code which returns the token
//Function to Get Access Token
public static function getFacebookToken($appid = self::fb_appid, $appsecret = self::fb_secret) {
$args = array(
'grant_type' => 'client_credentials',
'client_id' => $appid,
'client_secret' => $appsecret,
'redirect_uri' => 'https://www.facebook.com/connect/login_success.html',
'scope' => 'publish_stream,offline_access'
);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
try {
$data = curl_exec($ch);
} catch (Exception $exc) {
error_log($exc->getMessage());
}
return json_encode($data);
}
If I uncomment $token = $facebook->getAccessToken(); in the posting code, it gives me yet another error (#200) The user hasn't authorized the application to perform this action.
The token I get using
developers.facebook.com/tools/explorer/ is of another form, much longer and with it I am able to post to the group page feed.
How do I do it without copy/paste from Graph API Explorer and how do I post as a group instead of posting as a user?
Thanks.