开发者

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

开发者 https://www.devze.com 2023-02-05 14:57 出处:网络
Sample code is app开发者_Python百科reciated, I can\'t seem to find any simple examples of this online.Using the new Facebook PHP-SDK, it\'s very easy to accomplish this.

Sample code is app开发者_Python百科reciated, I can't seem to find any simple examples of this online.


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:

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

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

精彩评论

暂无评论...
验证码 换一张
取 消