简体   繁体   中英

Facebook and php - how to post content from my site to my facebook wall?

I'm very confused with this facebook api.

I've facebook username and password in my database, I want to sign and post content from my site to my facebook wall. how do I do it?

I've downloaded the facebook-php-sdk, just need to be able to include the "post" part in my php file to make things happen, I've this code at the moment

require_once ('facebook.php');
                $app_id = "MY_ID";
                $app_secret = "MY_SECRET";
                $facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));

                if(is_null($facebook->getUser())) {

                    header("Location:{$facebook->getLoginUrl(array('req_perms' => 'user_status,publish_stream,user_photos'))}");
                    exit;
                } 

                $status = $facebook->api('/me/feed', 'POST', array('message' => utf8_encode($my_message)));

with this I just get a internal server error, nothing more to have an idea of what I'm doing wrong...

even with var_dump($status) I get nothing Thanks

You cannot log in as a user on the Facebook Graph API. You should never be asking for any user's Facebook password in the first place, which is why Facebook do not allow this.

The API allows you to log in as an 'app', which can be granted permissions by Facebook users. You will need to create a Facebook app at https://www.facebook.com/developers/apps.php .

Once this is done, you can prompt a user to post on their wall or use the Graph API using http://developers.facebook.com/docs/reference/dialogs/feed/

Firstly try (i hope you entered your $app_id and $app_secret):

require_once ('facebook.php');
$app_id = "MY_ID";
$app_secret = "MY_SECRET";
$facebook = new Facebook(array('appId' => $app_id, 'secret' => $app_secret, 'cookie' => true));
$user = $facebook->getUser();

var_export($user);

You should se data if you're logged in properly.

Than you should maybe look at this page for an example Facebook Graph API PHP SDK posting on page as page

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