I have a job site where 100 jobs posting daily. i also have a Facebook page. i want to post 10 jobs each hour to My Facebook page with cron jobs. I am using the following code to post to Facebook face by accessing the URL Manually.
<?php
require_once 'facebook_sdk/src/facebook.php';
// configuration
$appid = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$pageId = 'xxxxx';
$msg = 'test';
$title = 'pagetitle';
$uri = 'http://google.com/';
$desc = 'description here';
$pic = 'http://google.com/test/2.png';
$action_name = 'Go to my site';
$action_link = 'http://www.google.com';
$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;
?>
It working fine. but i want to post the jobs automatically with corn jobs. how can i do it. does anyone have any advice?