sabato 18 maggio 2013

Post on Facebook wall with PHP

Here is a simple PHP page that takes care to publish a post on facebook through php.

Download the Facebook SDK for PHP from here: https://github.com/facebook/facebook-php-sdk;

Insert the SDK folder on your server.

Create a page called PostFacebook.php and stick the following code:

<? php
require 'facebook-php-sdk-master/src/facebook.php';
$ app_id = 'Your App ID';
$ app_secret = 'Your App Secret';
$ facebook = new Facebook (array (
'appId' => $ app_id,
'secret' => $ app_secret,
));


$ user = $ facebook-> getUser ();


if ($ user == 0) {

$ login_url = $ facebook-> getLoginUrl ($ params = array ('scope' => "publish_stream"));

echo ("<script> top.location.href = '". $ login_url. "' </ script>");

} Else {$ token = $ facebook-> getAccessToken ();

   try {
         $ post = $ facebook-> api ("/ me / feed", "POST", array (

             'message' => "Message Body",
             'name' => "Post Title"
             'caption' => "Caption Zone"
             'description' => 'Description',
             'link' => "www.miosito.it"
             'picture' => "www.miosito.it / mypicture.png"
         ));
   }
    catch (FacebookApiException $ e) {
       $ result = $ e-> getResult ();
      }
   }
?>

Alter them voices "'message', 'name', 'caption', 'description', 'link', 'picture'" with the content you want to publish on the bulletin board and you're done, you can publish on Facebook wall using PHP!

Nessun commento:

Posta un commento