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:
- Extended Permissions, depending on your needs
- 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);
精彩评论