Downloads

Google Ad

CakePHP Facebook Plugin -- v3.0 OAuth and Registration

Date: Mon, Aug 15th 2011, 12:40 Author: nick Views: 26014 Comments share

CakePHP Facebook Plugin

Info:
Get it:
  • Download Now
  • git clone git://github.com/webtechnick/CakePHP-Facebook-Plugin facebook

UPDATE 3


This update is now complete, all changes have been merged into master and you should update your plugins accordingly. The newest version is v3.1.1. Thank you all for your patience and continued support of the plugin.


UPDATE 2

I've forced the master branch of the plugin to be version v2.5.0 (the stable version). You can simply checkout the plugin normally to see the currently stable and functional version v2.5.0. All the 3.0 changes have been merged into a new branch called php_sdk_3. I will be updating and testing this branch and will not release it back to master until all features are working 100%. I will keep you updated as I make progress.

For now, simply checkout the master version of the plugin for the latest stable release.
  1. $ cd path/to/plugin/repository
  2. $ git checkout master

Thanks,
Nick

UPDATE

It appears I've jumped the gun a bit on the upgrade to v3.0. Looks like the good folks at Facebook still haven't linked up the fbxml and the PHP SDK entirely, leaving some features to partially work and others to be flat out broken. Until these issue are resolved please use the v2.5.0 version of the plugin.

For the time being please use the tagged version v2.5.0 of the plugin.

  1. $ cd path/to/plugin/repository
  2. $ git checkout v2.5.0

Or you can simply download it directly from here:
https://github.com/webtechnick/CakePHP-Facebook-Plugin/zipball/v2.5.0

I will be keeping a close eye on this and be update this blog post as well as the plugin as soon as I iron out all the issues the upgrade to 3.0 has caused.

Thanks for your understanding.

Original Post...


Two blog posts in one week! You're in for a special treat! Facebook finally updated their PHP SDK v3 to talk to their Javascript SDK which was holding the plugin back from updating along with the Facebook OAuth system. Now that Facebook has updated their PHP SDK, The plugin has been updated accordingly. By updated your plugin you won't be affected by the October 1st OAuth only deadline. Please update your plugin to be sure your app wont be locked out on October 1st 2011.

In addition to utilizing OAuth, there are two new features in version 3.0.

1) Send Button -- easily send the current page to a friend via email

2) Facebook Pre Populated Registration forms.

So without further adieu, lets get into it.

Send Button

Send buttons are new social media plugins to easily share a page via email (no facebook credentials required).

  1. //Show a send button default to current page.
  2. $this->Facebook->sendButton();
  3.  
  4. //Show a send button to a custom page
  5. $this->Facebook->sendButton('http://www.webtechnick.com');
  6.  
  7. //Show a send button with custom options
  8. $this->Facebook->sendButton('http://www.webtechnick.com', array(
  9.   'colorscheme' => 'dark'
  10. ));

Facebook Registration

New social media registration plugin allows a user to fill out a registration form auto-populated by their information in their Facebook profile. The setup is simple. Use the FacebookHelper::registration() to show the registration form in an iframe.

  1. //Show registration form with default fields
  2. $this->Facebook->registration();
  3.  
  4. //Show registration form with custom fields and width
  5. $this->Facebook->registration(array(
  6.   'fields' => 'name,email,location,gender,favorite_team',
  7.   'width' => '500'
  8. ));

By default, once the user clicks "Register" the post is sent back to the same page the registration form was shown on. In your controller action simply check for registrationData and do with the data what you will (create/update a user etc...)

  1. function registration(){
  2.   if($user = $this->Connect->registrationData()){
  3.     //We have a registered user, look at it and do something with it.
  4.     print_r($user);
  5.   }
  6. }

You can change where you want the user to post to by setting 'redirect-uri' in the registration helper method.

  1. //Show registration form with custom url
  2. $this->Facebook->registration(array(
  3.   'redirect-uri' => 'http://www.example.com/facebook_registration',
  4. ));

Hope you enjoy! As always, donations are appreciated.