Loadsys

LoadStr - A Loadsys Blog

A Web Development Company Specializing In Standard-Based Web Design and the CakePHP Framework.

CakePHP Social Networking Plugin

We started working on Socnet plugin that will allow your cake apps to be easily integrated with most social network sites. For now, we coded and released FacebookAuth component, which will allows to specify which actions require facebook authentication and redirects to facebook for authentication.

Installation

To add FacebookAuth component to your project, please do the following:

1. Download the plugin code from http://github.com/loadsys/socnet and extract all the code into plugins/socnet.

2. Create an application with Facebook at http://www.facebook.com/developers/createapp.php. Set your Connect URL to <your URL>/socnet/facebook/connect.

3. Add the following configuration paramters (Configure::write):
Socnet.Facebook.enabled[0,1] - a flag to disable/enable Facebook support
Socnet.Facebook.api_key - application key (from Facebook)
Socnet.Facebook.app_secret - application secret (from Facebook)

Controller Requirements

Load FacebookAuth component where needed and specify actions that require facebook authentication:

class FacebookFriendsController extends AppControoler {
var $components = array('socnet.FacebookAuth');
var $helpers = array('socnet.Facebook');

function beforeFilter() {
parent::beforeFilter();
$this->FacebookAuth->requireLogin('index');
}

function index() {
...
}
}

Layout Requirements

Facebook helper provides all the methods needed to setup Facebook in your layout.

# Use <?php echo $facebook->htmlTag(); ?> to render the html tag. This function will setup all necessary namespaces.
# Include this line <?php echo $facebook->jsScript(); ?> somewhere in the body. This library is needed for rendering FBML scripts (ex. <fb:connect-button />).
# Add this line <script type=”text/javascript”><?php echo $facebook->jsInit(); ?></script> before </body> tag.

Please look at the sample layout file in views/layouts/facebook.ctp inside the provided plugin.

You can test the plugin integration by going to /socnet/facebook/friends. If everything is setup properly, you should get redirected to facebook for login and then see all your friends thumbs.

Share This

Tags: , , ,

5 Responses to “CakePHP Social Networking Plugin”

  1. Jeff Says:

    Trying this out - but getting API errors when I click the connect button on the socnet/facebook/friends page.

    I added the configure::write settings to bootstrap.php - where do they need to be?

    Also, is the connect url correct? I can’t see the xd_receiver.html at
    mydomain.com/socnet/facebook/connect/xd_receiver.html
    I see it at mydomain.com/socnet/facebook/xd_receiver


  2. lee Says:

    Hi Jeff,

    I’ll have to ask our lead developer, Donatas, to look into this further, but do you have the following in your routes.php?

    Router::parseExtensions();

    That may be needed. If not, I’ll get back to you tomorrow.

    Lee


  3. Jeff Says:

    It wasn’t but I don’t think that was the problem.

    A more complete code example with download might be helpful.

    It sort of worked but had problems. Log out of facebook and come back to the page gave session errors.

    The FB Connect button appeared even after log in. State wasn’t clear.


  4. Brent Says:

    This looks great, I’m give it a shot :)


  5. William Says:

    did plug in support iframe with session, i’m creating facebook iframe apps with cakephp, but stuck in php session. any suggest will be helpful


Leave a Reply

Fill out the following to submit a comment.





Close
E-mail It