3

Sample code is appreciated, I can't seem to find any simple examples of this online.

ensnare
  • 40,069
  • 64
  • 158
  • 224
  • I wrote an article about this recently. You need to get extended_access permission and essentially post as an authenticated user that is an admin of the page. http://www.typeoneerror.com/articles/post/permanent-facebook-sessions-and-posting-as-a-page – typeoneerror Jan 19 '11 at 05:49

2 Answers2

3

Using the new Facebook PHP-SDK, it's very easy to accomplish this.

Requirements:

  1. Extended Permissions, depending on your needs
  2. Page ID

Now as I said, depending on your requirements you may need offline_access, manage_pages, but for now this is the simplest straight forward way of doing this:

After downloading the PHP SDK, and in the example.php file:

  • Acquire the publish_stream permission:

    <fb:login-button perms="publish_stream"></fb:login-button>  
    
  • After successful authentication, you post to the page wall the same way you do it for normal user profile (and with the same options too, message, picture, link, name, caption, description, source):

    $page_id = '123456789';
    $feed_array = array(
        'message' => "Hello world!"
    );
    $page_post = $facebook->api("/$page_id/feed","post",$feed_array);
    

Result:
alt text

Please note that this approach requires you being an administrator of the page.

ifaour
  • 38,035
  • 12
  • 72
  • 79
0

in this change the /me/feed/ to your page id, I did't try....Just check

$attachment = array('message' => 'some meesgae',
        'name' => 'This is my demo Facebook application!',
        'caption' => "Caption of the Post",
        'link' => 'mylink.com',
        'description' => 'this is a description',
        'actions' => array(array('name' => 'Get Search', 'link' => 'google.com')) );
    $result = $facebook->api('/me/feed?access_token='.$access_token, 'post', $attachment);
Damodaran
  • 10,882
  • 10
  • 60
  • 81