简体   繁体   中英

How can I post to the wall of a Facebook Fan Page using PHP and Open Graph API

示例代码表示赞赏,我似乎无法在网上找到任何简单的例子。

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:
替代文字

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM