I'm using facebook's php SDK and I'm trying to post on a page which is managed/administered by the logged in user. I've granted the publish_stream and manage_pages permission. And I want that the post should look like it is made by page rather than admin or logged in user. I've tried several helps but no one is working. Here is my part of my existing code:
require './php-fb-sdk/facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook( array('appId' => 'xxxx', 'secret' => 'zzzz'));
// Get User ID
$user = $facebook -> getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook -> api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
$params = array("scope" => array("manage_pages", "publish_stream"));
// Login or logout url will be needed depending on current user state.
if ($user) {
// Fetch the viewer's basic information
$basic = $facebook -> api('/me');
$permissions = $facebook -> api("/me/permissions");
if (array_key_exists('manage_pages', $permissions['data'][0]) && array_key_exists('publish_stream', $permissions['data'][0])) {
$admin_pages = $facebook -> api(array('method' => 'fql.query', 'query' => "SELECT page_id, type from page_admin WHERE uid=me() and type!='APPLICATION'"));
if (count($admin_pages) > 0) {
$post_info = $facebook -> api('/' . $admin_pages[0]["page_id"] . '/feed', 'post', array("caption" => "From web", "message" => "This is from my web at: " . time()));
echo '<hr>The post info is: ' . print_r($post_info, true) . '<hr>';
} else {
echo '<hr> You are not admin of any fb fan page<hr>';
}
//print_r($admin_pages);
} else {
// We don't have the permission
// Alert the user or ask for the permission!
header("Location: " . $facebook -> getLoginUrl(array("scope" => "manage_pages,publish_stream")));
}
$logoutUrl = $facebook -> getLogoutUrl();
} else {
//$statusUrl = $facebook->getLoginStatusUrl();
$loginUrl = $facebook -> getLoginUrl($params);
$statusUrl = $loginUrl;
}
Using the above code I can post on the page but it looks like it is made by user.
However if I use facebook JS SDK then I see the post looks like it is made by the page.
var data=
{
caption: 'My Caption',
message: 'My Message'
}
FB.api('/' + pageId + '/feed', 'POST', data, onPostToWallCompleted);
}
Any help or suggestions will be greatly appreciated.