<?php
require_once 'facebook_sdk/src/facebook.php';
// configuration
$appid = 'тут id приложения, я ее создал';
$appsecret = 'тут секретный код';
$pageId = 'тут id страницы владельца, как я понял';
$msg = 'test';
$title = 'тут тайтл';
$uri = 'http://karabakhtimes.ru/';
$desc = 'description here';
$pic = 'http://karabakhtimes.ru/media/Samiy-tochniy-goroskop-na-segodnya.jpg';
$action_name = 'Go to my site';
$action_link = 'http://karabakhtimes.ru/samyj-tochnyj-goroskop-na-segodnya.html';
$facebook = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => false,
));
$user = $facebook->getUser();
// Contact Facebook and get token
if ($user) {
// you're logged in, and we'll get user acces token for posting on the wall
try {
$page_info = $facebook->api("/$pageId?fields=access_token");
if (!empty($page_info['access_token'])) {
$attachment = array(
'access_token' => $page_info['access_token'],
'message' => $msg,
'name' => $title,
'link' => $uri,
'description' => $desc,
'picture'=>$pic,
'actions' => json_encode(array('name' => $action_name,'link' => $action_link))
);
$status = $facebook->api("/$pageId/feed", "post", $attachment);
} else {
$status = 'No access token recieved';
}
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
} else {
// you're not logged in, the application will try to log in to get a access token
header("Location:{$facebook->getLoginUrl(array('scope' => 'photo_upload,user_status,publish_stream,user_photos,manage_pages'))}");
}
echo $status;
?>