How can I post an article on my Facebook Fan page using PHP and the Open Graph API

Sample code appreciated, I cannot find simple examples of this online.

+3
source share
2 answers

Using the new Facebook PHP-SDK is very easy to do.

Requirements:

Now, as I said, depending on your requirements you may need offline_access, manage_pagesbut at the moment it is the easiest way to do this:

After loading the PHP SDK and in the file example.php:

  • Get permission publish_stream:

    <fb:login-button perms="publish_stream"></fb:login-button>  
    
  • , user ( , 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);
    

:
alt text

: , .

+3

/me/feed/ , ...

$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

Source: https://habr.com/ru/post/1786261/


All Articles