I got the code below from another website which seems to be working fine. The only problem is that posts appear on the "POSTS TO PAGE" section of the Facebook page instead of appearing on the page timeline directly.
Any idea why?
Also, the code works when I use the access token, not the app access token. When using app access token, I get an error message saying: "(#200) The user hasn't authorized the application to perform this action"
<?php
// require Facebook PHP SDK
// see: http://ift.tt/1fCaYUH
require_once("/YOUR_PATH_TO/facebook_php_sdk/facebook.php");
// initialize Facebook class using your own Facebook App credentials
// see: http://ift.tt/1n65vdg
$config = array();
$config['appId'] = 'YOUR_APP_ID';
$config['secret'] = 'YOUR_APP_SECRET';
$config['fileUpload'] = false; // optional
$fb = new Facebook($config);
// define your POST parameters (replace with your own values)
$params = array(
"access_token" => "YOUR_ACCESS_TOKEN", // see: http://ift.tt/L1kwN8
"message" => "Here is a blog post about auto posting on Facebook using PHP #php #facebook",
"link" => "http://ift.tt/1hBHVQg",
"picture" => "http://ift.tt/1hBHVQj",
"name" => "How to Auto Post on Facebook with PHP",
"caption" => "www.pontikis.net",
"description" => "Automatically post on Facebook with PHP using Facebook PHP SDK. How to create a Facebook app. Obtain and extend Facebook access tokens. Cron automation."
);
// post to Facebook
// see: http://ift.tt/1p38EHk
try {
$ret = $fb->api('/YOUR_FACEBOOK_ID/feed', 'POST', $params);
echo 'Successfully posted to Facebook';
} catch(Exception $e) {
echo $e->getMessage();
}
?>
Aucun commentaire:
Enregistrer un commentaire