Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Post on a Facebook wall as Page, not as user

Is it possible to post on a Facebook wall as application and not as user? As far as I understand an application is not a valid user for Facebook, but there are numerous comments about posting as Page and not as User or Application.

How can I do it using PHP Facebook API?

like image 502
WASD42 Avatar asked Mar 16 '11 14:03

WASD42


People also ask

How can I post as a page not as my personal account?

Log into Facebook and go to the page you administer. Above option “Create Post,” in the upper right corner is located your page's logo – click on it and switch accounts. Select the name of the profile you want to comment as.

How do I change who I am posting as on Facebook?

To change whether you interact as your profile or your Page in your group: Tap your profile picture at the bottom right of Facebook. Tap Select Profile. Select the profile or Page you want to interact as.

How do you switch between posting as a profile and posting as a page?

A Page you manage must be linked to your group in order to post from your Page. Tap in the bottom right of Facebook and tap Groups then Your groups, then select your group. If you don't see Groups, tap See more. In the bottom right, tap the circle with your profile picture and select your Page or your profile.

Can I post in other Facebook as a page?

#2: Post on Facebook Pages as Your Page Choose which page you want to post with. If you want to post as a page you manage within Business Manager, you'll need to scroll down to the bottom of the list and click on your Business Manager account. Scroll down further to select your Business Manager account.


2 Answers

You need the publish_stream,manage_pages permissions. The code is something like:

<?php
// This code is just a snippet of the example.php script
// from the PHP-SDK <https://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php>
require '../src/facebook.php';

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'app_id',
  'secret' => 'app_secret',
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    $page_id = 'page_id';
    $page_info = $facebook->api("/$page_id?fields=access_token");
    if( !empty($page_info['access_token']) ) {
        $args = array(
            'access_token'  => $page_info['access_token'],
            'message'       => "I'm a 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])) {
            // We don't have one of the permissions
            // Alert the admin or ask for the permission!
            header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream, manage_pages")) );
        }

    }
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl(array('scope'=>'manage_pages,publish_stream'));
}

// ... rest of your code
?>

I've written and in-depth tutorial about this: How To: Post On Facebook Page As Page Not As Admin User Using PHP-SDK

like image 128
ifaour Avatar answered Oct 13 '22 17:10

ifaour


You must first have a user authorize via facebook connect, and request the manage_pages permission as a part of this request. You can use this permission to obtain a token and secret for the page in question. You then use those to authorize requests as opposed to the token/secret you received for the user.

Check out the "Page Login" section of this page for some additional info: http://developers.facebook.com/docs/authentication/

like image 29
Wade Tandy Avatar answered Oct 13 '22 18:10

Wade Tandy