1,105,352 Community Members

Post to page as page when user is connected to App

Member Avatar
karen.frias0316
Newbie Poster
16 posts since Oct 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article