Reputation: 3170
Anyone knows how to Posting in Facebook Business Page Wall as ANYONE of administrative user (who has privileged as "Manager")? I have created some test account on behalf of my client. And use it's ID as "APP_ID". If I post via that account, it is working fine. But can not post by using any other "manager" privileged user account.
$config = array(
'appId' => $APP_ID,
'secret' => $APP_SECRET
);
$facebook = new Facebook($config);
$fbuser_id = $facebook->getUser();
I am using the above code. As per that, need to pass pre-defined user id as a app_id.
Is there any way to get current logon user id?
Upvotes: 1
Views: 113
Reputation: 3170
I found the solution.
Have to get the access_token for that particular page under that logged on user.
$result = $facebook->api("/me/accounts");
// loop trough all your pages and find the right one
if( !empty($result['data']) )
{
foreach($result["data"] as $page)
{
if($page["id"] == $page_id)
{
$page_access_token = $page["access_token"];
break;
}
}
}
Set the access_token to facebook object
$facebook->setAccessToken($page_access_token);
After that call "post" function.
$msg = array(
'message' => 'Message body',
'caption' => 'This is Title',
'link' => 'http://www.yoursite.com/page/$i',
'picture' => 'http://www.yoursite.com/images/logo.jpg');
$postResult = $facebook->api('/'.$page_id.'/feed', 'post', $msg );
Note: If access_token not configured; post messages will be posted for any 'manager' role user to the FB page without 'link' attribute of the message. if you add 'link' attribute to the post message, that will not be posted!
Upvotes: 1