Topic-icon Custom php and javascript

Active Subscriptions:

None
13 years 3 months ago #31373 by fb_100000532508192
Hi i'm using jfbconnect v5,

i would like to make custom calls to facebook api via the jfbconnect library. So far i can use:
require_once JPATH_ROOT.DS.'components'.DS.'com_jfbconnect'.DS.'libraries'.DS.'facebook.php';
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance();
$post = 'is doing something';
$post = 'www.sourcecoast.com/jfbconnect';
//if ($jfbcLibrary->getUserId()) // Check if there is a Facebook user logged in
$jfbcLibrary->setFacebookMessage($post);

i have also commented out the 'if ($jfbcLibrary->getUserId())' as this produces an error with v5 and is not used in the v5 modules.
What is the equvilant javascript for above?
What would be the best way to post(php and javascript) to an offline user if the joomla user id is known?

Many thanks in advance
The topic has been locked.
Support Specialist
13 years 3 months ago #31380 by alzander
Replied by alzander on topic Custom php and javascript
You can replace that userID check with $jfbcLibrary->userIsConnected() to simply check if there is a user logged in. We had multiple "getID" type functions previously that were pretty confusing.

Just so you are aware, Facebook recently changed some of their Application Policies. With Open Graph Actions out now, which are meant to post messages on the user's behalf when they interact with your site, you are not supposed to do /feed posts anymore where the message is pre-filled in or where the user isn't aware the post will be made. In the 5.0 release, we still have the ability to post on login and register, but we have a notice at the top mentioning the change and that we no longer recommend using the feature. Additionally, if you want to post to the user's wall, you'll need to add the publish_stream permission to the Additional Permissions field as JFBConnect wont' automatically request that permission anymore.

With all that said, if you want to post using Javascript, you can use an undocumented call in JFBConnect: jfbc.social.feedPost

The definition is:
feedPost:function (title, caption, description, url, picture)
With that, you can create a button or invoke Javascript to show a popup for the user with a pre-filled (editable) message and other information, like:
<a href="#" onclick="jfbc.social.feedPost('Phil's Page', 'Come look at what I found!', 'This great page features dynamically generated images you might like', 'http://yoursite.com', 'http://yoursite.com/link-to-image.jpg');">Click me to share!</a>

Hope that helps get you started and gives you more information. Should you need anything else, let us know.

Alex
The topic has been locked.
Active Subscriptions:

None
13 years 3 months ago #31386 by fb_100000532508192
Thank you for your reply. Do you have code examples for offline php/JavaScript.

Thanks in advanced
The topic has been locked.
Support Specialist
13 years 3 months ago #31442 by alzander
Replied by alzander on topic Custom php and javascript
I don't have any for Javascript. The JS API is very 'self centric', so if the user is offline, that won't work.

The following should work though through PHP assuming the user has logged in and approved the stream_publish permission:
$userMapModel = new JFBConnectModelUserMap();
$fbUser = $userMapModel->getData(200); // Get the JFBConnect data for Joomla user with ID 200;
$jfbcLibrary = JFBConnectFacebookLibrary::getInstance(); 
$post['message'] = 'is doing something'; 
$post['link'] = 'http://www.sourcecoast.com/jfbconnect'; 
$post['access_token'] = $fbUser->access_token;
$jfbcLibrary->setFacebookMessage($post);
I haven't tested that code, but really, setting the access_token variable is the only thing you'd need to do. JFBConnect will default it to the current user's access_token if you don't set one in the params, like we do above.

Good luck,
Alex
The topic has been locked.