I\'m trying to publish checkin using Facebook Graph API. I\'ve gone through Facebook API documentation (checkins) and also have the publish_checkins
permission.
Apparently, the configuration and the PHP checkin function that I have posted in the question are correct. However, I should use JavaScript SDK instead of PHP SDK for my case as pointed out by Nehal. For future references...
Using JavaScript SDK
function checkin()
{
FB.api('/me/checkins', 'post',
{ message: 'MESSAGE_HERE',
place: 165122993538708,
coordinates: {
'latitude': 1.3019399200902,
'longitude': 103.84067653695
}
},
function (response) {
alert("Checked in!");
}
);
}
You also need to learn PHP and variable scoping.
$facebook = new Facebook(array(
'appId' => FB_API_KEY,
'secret' => FB_SECRET_KEY,
'cookie' => true,
));
$loginUrl = $facebook->getLoginUrl(
array('scope' => 'status_update,publish_stream,publish_checkins,user_checkins,user_location,user_status,user_checkins')
);
// Session based API call
if ($user) {
try {
$me = $facebook->api('/me');
if($me)
{
$_SESSION['fbID'] = $me['id'];
}
} catch (FacebookApiException $e) {
error_log($e);
}
}
else {
echo "<script type='text/javascript'>top.location.href='$loginUrl';</script>";
exit;
}
function checkin($fb)
{
try
{
$tryCatch = $fb->api('/'.$_SESSION['fbID'].'/checkins', 'POST', array(
'access_token' => $fb->getAccessToken(), //corrected
'place' => '165122993538708',
'message' =>'I went to placename today',
'coordinates' => json_encode(array(
'latitude' => '1.3019399200902',
'longitude' => '103.84067653695'
))
));
}
catch(FacebookApiException $e)
{
$tryCatch=$e->getMessage();
}
return $tryCatch;
}
checkin($facebook); //calling the function and passing facebook object to function