1.11M Members

Post to page as page when user is connected to App

 
0
 

Hi! I have a code which posts to page wall as page when admin access the app. I was able to get the page access token and give manage_pages permission using this https://developers.facebook.com/tools/explorer/ . Now i want it to still post as page to the page wall when other users access the app too. I've been searching and coding for couple of hours now but still not getting what is wanted. Can anyone help me how to do it? Your help is very much appreciated.

require 'libs/facebook.php';
$facebook = new Facebook(array(
    'appId'  => 'xxxxxxxxxxxxxx',
    'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$loginUrl = $facebook->getLoginUrl();
$user = $facebook->getUser();

$page_id = 'xxxxxxxxxxxx';
$page_info = $facebook->api("/$page_id?fields=access_token");


if( !empty($page_info['access_token']) ) {
    $args = array(
        'access_token'  => $page_info['access_token'],
        'message'       => "Post! User clicks page"
    );
    $post_id = $facebook->api("/$page_id/feed","post",$args);
} else {
    $permissions = $facebook->api("/me/permissions");
    if( !array_key_exists('publish_stream', $permissions['data'][0]) || 
        !array_key_exists('manage_pages', $permissions['data'][0])) {
        header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
    }

}
You
Post:
Start New Discussion
Tags Related to this Article