GET /{user-id}/likes/{page-id}//facebook page id
$page_id = "322357214479732";
//checking if user is logged in and then get fb user id
if ($fbid = JFBCFactory::provider('facebook')->getMappedUserId()){
//check if current user is fan of page, if not then show like box
$result = $jfbcLibrary->api($fbid . '/likes/. $page_id);
if ($result['data']) // May need to look for a specific value in here or if the count of ['data'] is > 0 may be good.
echo 'Yup, they like it';
}FB.api('/me/likes/322357214479732', function(response) {
console.log(response);
if (response['data'])
alert("Yup, they like it");
});Depending on how JFBConnect is configured for login (using popup or not), the token may not be generated yet.The Facebook SDK for Javascript generates and persists access tokens automatically. You can learn more about starting the login process in our guide: Getting Started with Facebook Login for Web. You can retrieve the access token by making a call to FB.getAuthResponse which will include an accessToken property within the response.
FB.getAuthResponse();Ahh.. yeah, if you have the "Automatically Log In Facebook Users" setting disabled, we set status:false. It has a minor performance impact when enabled and since we don't need to the Javascript token updated on every page load, we take advantage of that. We're very performance conscience. this is due to fb.init (status) being false(i assume this is due to less calls being made to fb with am impact on page load times).
There's a few options:So i guest my question is. How do you update jfb with the new token from javascript?
FB.getLoginStatus(function (response)
{
if (response.status === 'connected')
{
// DO SOMETHING
}
}Unfortunately, we can't update to the latest Facebook SDK yet because it requires PHP 5.4. That's higher than the minimum level for even Joomla 3.x, which means we likely won't be updating to that version anytime soon.Also found this article which seems to have a very good way of handling tokens with php and javascript. not sure if you guys implement sessions this way?
Join our newsletter to get alerts for Joomla releases, tips and tricks and extension updates.
