× Joomla Facebook Connect support forum

Topic-icon Using $pushfacebook

Active Subscriptions:

None
12 years 8 months ago #12672 by gedmonstone
Can anyone help. I am using the $pushfacebook function within my code to allow users to push detail to thir wall. It works fine under the following condition:-

User 1 is logged into Facebook
User 1 is logged into Kumbooka

However, if User 2 is logged into Facebook, and User 1 is logged into Kumbooka, the details pushed from Kumbooka by User 1 appear on User 2's Facebook wall. Further to this, it appears as if User 2 posted it, rather than User 1 who did the actual post from Kumbooka.

My guess is that we are finding out the user that is logged into Facebook, rather than the user that is logged into Kumbooka, and then doing the push.

How can I resolve this issue?

The actual code I am using is the following

$pushfacebook = JRequest::getInt('pushfacebook',0);

if ($pushfacebook) {

require_once JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php';
ob_start();
$jfbuser = JRequest::getInt('user_id', 0);
$title = JText::sprintf(" %s %s", $itemstatus, $stuff->jr_title);
$jfbname = JText::sprintf(" %s", $stuff->jr_title);
$jfbcaption = "socialise your stuff at Kumbooka.com";
$jfburl = "www.kumbooka.com/index.php?option=com_kb...=contentdetail&asin=". $stuff->jr_asin;
$jfbimages = $stuff->jr_mediumimage;
$jfbvideo = "www.youtube.com/v/". $stuff->jr_youtube;
$jfbactions = "{'name':'View my full collection','link': 'www.kumbooka.com/index.php?option=com_co...d=$jfbuser&Itemid=93'}";
if(isset($stuff->jr_youtube))
$vals = array("message"=>$title, "picture"=>$jfbimages, "link"=>$jfburl, "name"=>$jfbname, "caption"=>$jfbcaption, "source"=>$jfbvideo, "actions"=>$jfbactions);
else
$vals = array("message"=>$title, "picture"=>$jfbimages, "link"=>$jfburl, "name"=>$jfbname, "caption"=>$jfbcaption, "actions"=>$jfbactions);

$fbLibrary = JFBConnectFacebookLibrary::getInstance();
$fbLibrary->setFacebookMessage( $vals );

//echo 'alert("Hi");';

$html = ob_get_contents();
ob_end_clean();
$result->facebook = $html;

} else {
$result->facebook = '';
}
} else {
$result->result = $this->_db->getError();
$result->status = "Error";
}
//var_dump($table);
return $result;
}


Thanks for any advice anyone can offer.

Kind regards

Gary
The topic has been locked.
Support Specialist
12 years 8 months ago #12685 by alzander
Replied by alzander on topic Using $pushfacebook
Gary,
I just realized you sent a similar Private Message a bit ago that I never responded to. I apologize for the delay.

Looking at our code, I can actually see how this could be possible. Basically,
* Facebook sets a cookie on the user's computer with their FB Id
* JFBConnect, when trying to post, will use this cookie to post the user's wall
* JFBConnect will check that the cookie belongs to a user that has an account on the site, but not that it's the current user logged in

The above means that if both the Facebook user has a Joomla account, but isn't logged into it.. but are logged into Joomla with another account, JFBConnect could confuse the two. I haven't tested this, and can't guarantee it's the problem you're having, but sounds like it. We do other tests before we post to the wall to prevent this behavior, but if you're calling setFacebookMessage directly, you'll have the problem.

To fix, we'd recommend you add the following line right above your setFacebookMessage line:
if ($fbLibrary->getMappedFbUserId())
  $fbLibrary->setFacebookMessage(...)
The getMappedFbUserId will check the current Joomla user against their mapped Facebook ID to make sure they are the same. If not, it will return null.

Please note, this will only work in 3.4.0 and 3.4.1. Previous to that, you should use $fbLibrary->getUserId(true) which will do the same, but we didn't like the passing of the true/false parameter to do the validation against the Joomla ID, and so therefore, broke it into two functions.

Hope this helps, and again, sorry for the non-response earlier.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
12 years 8 months ago #12694 by gedmonstone
Replied by gedmonstone on topic Using $pushfacebook
Thanks for the prompte reply Alex. I made the change you suggested, and it prevents User 1 posting to User 2's wall, great job. However, I have also noticed that the code I use will not post to Users 1's FB wall, if User 2 is currently logged into FB and User 1 into Kumbooka.

It appears that in order to work, I have to have the user logged into both Facebook and Kumbooka.

I am currently building a mobile app, and this means that the $pushfacebook as I use it, will never allow the user to push from the iPhone app.

Any thoughts on how I can modify the code in order to allow the push to Facebook, even if the user has already logged out of Facebook, but has stayed logged into Kumbooka?

Thanks again for the best Facebook connect product on the market, and keep up the good work Alex.

Regards

Gary
The topic has been locked.
Support Specialist
12 years 8 months ago #12703 by alzander
Replied by alzander on topic Using $pushfacebook
Gary,
That's the correct behavior with how JFBConnect was created. To post to a user's wall when they aren't logged into Facebook, you'd need the offline_access permission from the user. That's something we're planning to implement in an upcoming release of JFBConnect for a few other features and improvements it will allow us to do.

To do now would take a bit of development, but here's the general flow of what needs to be done to post to a user's wall who isn't logged into Facebook:
1) Get the offline_access prermission approved by the user
2) Store an access token for that user in the database when they do log into your site
3) When posting to the user's wall, use the access token to identify the user's wall that you want to post to, even if they aren't online at the time

The biggest deal, obviously, is storing and using the access token when necessary. We're working on a similar system already for LinkedIn, which does its tokens by default similar to what's described above, so when that's implemented, we'll hopefully be able to re-use some of that code inside JFBConnect.

It won't be in the next month that this is implemented, but we'd hope to have it in a release by the end of the year.

Hope that explains. If you really want to do it now, I'm sure we can give more details on how if necessary.

Thanks,
Alex
The topic has been locked.