I am trying to build an app where I let my registered user be able to check in to places on Facebook Places. I however for some reason can't seem to make this work. I assumed this is possible with the Api as write functionality has been added to it, but I couldn't find an clear explanation on the web. this is what I currently have, after I have asked the user for permission to publish checkins and for user_checkins.
<?php
require("src/facebook.php");
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true
));
# see if active session
$session = $facebook->getSession();
if(!empty($session)) {
try{
$uid = $facebook->getUser();
$api_call = array(
'method' => 'users.hasAppPermission',
'uid' => $uid,
'ext_perm' => 'publish_checkins'
);
$can_post = $facebook->api($api_call);
if($can_post){
$facebook->api('/'.$uid.'/checkins', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'place' => 'place_id',
'message' =>'I went to placename today',
'picture' => 'http://www.place.com/logo.jpg',
'coordinates' => array(
'latitude' => 'lattiude',
'longitude' => 'lattitude',
'tags' => $uid,
)
)
);
echo 'You were checked in';
} else {
die('Permissions required!');
}
} catch (Exception $e){}
} else {
# There's no active session,generate one
$login_url = $facebook->getLoginUrl();
header("Location: ".$login_url);
}
?>
The code works when I change it 'checkins' to 'feed'. Is there something wrong with my code or am I trying to do somethign that isn't possible (or do it the wrong way).
Any help will be greatly appreciated as I already spent quite a significant amount of time trying to fix this, but I just can't seem to make it work.
Best regards,
Marcus Joe
Your answer is almost correct.
$facebook->api('/'.$uid.'/checkins', 'POST', array(
'access_token' => $facebook->getAccessToken(),
'place' => 'place_id',
'message' =>'I went to placename today',
'picture' => 'http://www.place.com/logo.jpg',
'coordinates' => json_encode(array(
'latitude' => 'lattiude',
'longitude' => 'lattitude',
'tags' => $uid),
)
)
Notice that for coordinates you have to supply a json_encode variable. Hope that helps someone.
Just an update From Facebook:
NOTE: Publishing a Checkin object is deprecated in favor of creating a Post with a location attached.
You can check out how to create a Post with a location (or a Facebook Place id) here: http://developers.facebook.com/docs/reference/api/user/#posts
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With