FacebookApiException Object
(
[result:protected] => Array
(
[error] => Array
(
[message] => Invalid OAuth access token signature.
[type] => OAuthException
[code] => 190
)
)
[snipped]
Code:
<?php
require_once 'vendor/autoload.php'; //thank you Composer!
$appid = "597939046950715";
$appsecret = "854f9cbc2ce4a358938f72d65163fe77";
//Function to Get Access Token
function get_app_token($appid, $appsecret) {
$args = array(
'grant_type' => 'client_credentials',
'client_id' => $appid,
'client_secret' => $appsecret//,
//'scope' => 'manage_pages,publish_stream'
);
var_dump($args);
$ch = curl_init();
$url = 'https://graph.facebook.com/oauth/access_token';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
return json_encode($data);
}
// Create FB Object Instance
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => false,
));
echo "Made object<br>";
//Get App Token
$token = get_app_token($appid, $appsecret);
echo "<br>Got token: $token<br>";
//Try to Publish on wall or catch the Facebook exception
try {
$attachment = array(
'method' => 'publish_stream',
'message' => 'This is a message',
'access_token' => $token,
'name' => 'Attachment Name',
'caption' => 'Attachment Caption',
'link' => 'http://nyt.com',
'description' => 'Description .....',
'picture' => 'http://www.google.com/logo.jpg'
//'actions' => array(array('name' => 'Action Text',
//'link' => 'http://apps.facebook.com/xxxxxx/'))
);
echo "before call";
$result = $facebook->api('/'.$appid.'/feed/', 'post', $attachment);
echo $result;
} catch (FacebookApiException $e) { //If the post is not published, print error details
echo '<pre>';
print_r($e);
echo '</pre>';
}