Facebook Plugin v2.0 -- Graph System!
Date: Mon, Jul 19th 2010, 02:20 Author: nick Views: 1776 Comments: 48 share
Please Support:
CakePHP Facebook Plugin
Info:
- Version: 2.0.3
- Requirements: CakePHP 1.3, PHP5.1+
- Docs: CakePHP Facebook Plugin API
- Article: CakePHP Facebook Plugin Discussion and Examples
Get it:
Download Now
- svn co http://svn.github.com/webtechnick/CakePHP-Facebook-Plugin facebook
CakePHP Facebook Plugin v2.0 is here! With the help from Theaxiom (https://github.com/theaxiom) the popular CakePHP Facebook plugin is now updated to the newest PHP SDK which features among other things full access to the much anticipated Facebook Graph System.
Along with access to the new SDK, I've implemented some great new fbxml features
Some Examples of the newest features are:
Along with the newest Helper features there is an feature enhancement as well.
Example:
There are a few changes you should be aware of before upgrading your application to the newest version 2.0.
New Configuration File Example:
New ConnectComponent::user() Examples:
New Layout Example:
New API Examples:
I hope you all enjoy version 2.0. As always, if you like the plugin, have a question, concern, or feature request please post a comment.
If you use the plugin and want to help maintain it please consider a donation.
Enjoy!
Nick
New Features
Along with access to the new SDK, I've implemented some great new fbxml features
- Like (let your users like what they find on your site with their friends)
- Activity Feed (Display your application's and friends activity)
- Friend Pile (Display your application's friends)
- Recommendations (Display your recommendations based on your current url)
Some Examples of the newest features are:
- //Like Button
- $facebook->like(); // => standard like button
- 'font' => 'veranda',
- 'layout' => 'button_count',
- 'action' => 'recommend',
- 'colorscheme' => 'dark'
- )); // => customized like button
- //Activity Feed
- $facebook->activity(); // => app activity widget
- 'colorscheme' => 'dark',
- 'bordercolor' => 'black',
- 'font' => 'arial',
- 'width' => '250',
- 'height' => '200',
- 'header' => 'false',
- 'recommendations' => 'true'
- )); // => customzied activity widget including recommendations
- //Recommendations Widget
- $facebook->recommendations(); // => recommendations of current page
- 'colorscheme' => 'dark',
- 'bordercolor' => 'black',
- 'width' => '250',
- 'height' => '200',
- 'header' => 'false'
- )); // => customized recommendations widget
- //Friend Pile Widget
- $facebook->friendpile(); // => standard friend pile
- 'width' => 200,
- 'numrows' => 3
- )); // => customized friend pile
Feature Improvements
Along with the newest Helper features there is an feature enhancement as well.
- FacebookHelper::logout() Now accepts CakePHP array urls as valid redirect options
Example:
- //Normal logout
- 'redirect' => 'users/logout'
- ));
- //Same as above
- ));
1.x to 2.x Migration Guide
There are a few changes you should be aware of before upgrading your application to the newest version 2.0.
- FacebookHelper::loader() is now deprecated. Remove it from your layout.
- ConnectComponent::getUserInfo() is no longer available, use ConnectComponent::user() instead.
- config/facebook.php needs to be updated.
- FacebookHelper::init() no longer takes in extended permission options, remove any of these extended options from your $facebook->init() call in your layout.
- FacebookApi class is now FB for short use App::import('Lib','Facebook.FB'); for easy access to the full Facebook API.
New Configuration File Example:
- app/config/facebook.php
- 'appId' => 'YOUR_APP_ID',
- 'apiKey' => 'YOUR_API_KEY',
- 'secret' => 'YOUR_SECRET',
- 'cookie' => true,
- )
- );
New ConnectComponent::user() Examples:
- function beforeFilter(){
- //Get all the details on the facebook user
- $this->set('facebookUser', $this->Connect->user());
- //retrieve only the id from the facebook user
- $this->set('facebook_id', $this->Connect->user('id'));
- //retrieve only the email from the facebook user
- $this->set('facebook_email', $this->Connect->user('email'));
- }
New Layout Example:
- <?= $facebook->html(); ?>
- <head>
- <title>Facebook Plugin Example</title>
- </head>
- <body>
- <?php echo $content_for_layout ?>
- <?= $facebook->init(); ?>
- </body>
- </html>
New API Examples:
- App::import('Lib', 'Facebook.FB');
- //PHP 5.3
- FB::api('/me'); //graph system call to /me
- //PHP < 5.3
- $FacebookApi = new FB();
- $FacebookApi->api('/me');
Enjoy v2.0
I hope you all enjoy version 2.0. As always, if you like the plugin, have a question, concern, or feature request please post a comment.
If you use the plugin and want to help maintain it please consider a donation.
Enjoy!
Nick

V2.0.1
what's new in version 2.0.1 VS 2.0 ?
Thx ^^
2.0.1 Change Log in README.txt
If set to true (default) upon a successful facebook login, and the facebook_id is not found in the User table, the component will attempt to create a new user from introspection on the Auth component. Turn this feature off by passing in 'createUser' => false when setting up the Connect component.
Example usage:
Great Plugin
Retrieve & Insert Email & info
Great plugin. I've gotten pretty far developing my app. I am having one issue. I've read the documentation and your comments on the forum multiple times and I am still stuck.
Would it be possible to provide detailed instructions on how to retrieve the user info using the graph system? I seem to be having a problem figuring out how to access the facebook user info array.
I'd be willing to throw you some $$ for support as well.
Thanks in advance.
JM
Hi JM
So you can get your users information a number of ways. Each way requires your user to give your application rights to retrieve that information. You get those rights by getting the user to click the "Login" button. You can display this at anytime in your views with the facebook helper.
By clicking that button, your user is granting your application access to their facebook profile. Upon a successful Facebook.Connect login the $me property of the Facebook.Connect component will be populated with all the relative information for that logged in user.
It is then you can store whatever information you want/need from that user's profile and save it to your database.
The logged in facebook user is also set to the session variable FB which you can access anywhere within your application (model/view/controller).
Or you can use the built in FB class and access the graph system directly.
A simple example using the component would be something like this:
Hope that helps,
Nick
Get access token
Anyways, so I'm back to just using Facebook now.
I'm using your plugin to allow the user to login. What I'm trying to do now is create an event for one of the users groups.
The user selects a group that their are an admin of, and then my app attempts to create the group. The problem is the event is not getting created for the group, just the user.
I'm posting to path /
I'm wondering if the issue is because the auth token I have is for the logged in user and I need to get an auth token for my app?
If that is the case, how do I handle logging in the user via the plugin and then also creating events?
fbxml not working anymore after update from 1.x to 2.0.2
First I would like to thank you for the work you did coding this really usefull cake component, it just rocks.
I tried today to update it to the latest version that uses the Graph API and everything seems to work well except that no fbxml is being interpreted anymore.
I followed the upgrade guide.
According to the error log on firefox, it seems to be javascript related.
I have this error:
The code generated by $facebook->init(); is :
I try to figure it out but i'm stuck. Any idea ?
Thanks
Madjik
urgl
Madjik
fbxml not working anymore after update from 1.x to 2.0.2
I found the problem. It seems that the $facebook->share() fuction is broken in version 2.0.2.
When I use it on a page it brokes all other fbxml tags. Seems to be related to the javascript the share function generates.
If I replace de $facebook->share() with the fb:share-button, it works and the rest also works.
Strange :)
Interesting
By the way, the bbcode to use for code styling is:
geshi=php
code goes here.
/geshi
With brackets results in:
Thanks again,
Nick
Question :)
I''m getting into another "issue", talking about the init().
We could set the extended attributes we want to access on facebook when calling the init() function. But now it is not allowed anymore on v2.0.2.
How can we set those extended attributes with the new version ?
If i'm not wrong, I saw on the facebook developper that those parameters can be passed to the login button now ?
Updated 2.0.3 share
Facebook::share now takes in fbxml boolean option (default false). if true, Facebook::share will use the fbxml version of the share button instead of the default javascript version. The fbxml version will only work if Facebook::init() is called on the same page.
Extended Permissions:
You can ask for extended permissions through the Facebook API (Auth Token required) or you can ask through the Facebook::login() function (recommended).
Example:
For a full list of extended permissions, look here:
http://developers.facebook.com/docs/authentication/permissions
Hope that helps,
Nick
2.0.3 test
thank you for the changes in the 2.0.3.
It now works well with the fbxml share option.
There's just something that might be enhanced. The fbxml share tag supports many different forms of buttons. The helper is only accepting button or link.
But there are several others:
http://wiki.developers.facebook.com/index.php/Fb:share-button
/>
As for exemple i use button_count.
:)
quickfix
with
in the helper share function, so that it doesn't alter the option 'type' when using fbxml.
Error...
Fatal error: Call to a member function delete() on a non-object in /home/.../app/plugins/facebook/controllers/components/connect.php on line 68
It only happens if I have 'Facebook.Connect' as a component in app_controller.
Requires Session Component
Hope that helps,
Nick
Session login-logout loop
I meet a problem with fb login, when I using application outside facebook, login work but each action lost cookies and make logout. Inside facebook application make infinite loop login-logout. Someone meeet same problem?
Thanks
Stefano
about FBML tags
about FBML tags
Thanks for consideration....
connect/authorization url
Some answers.
@about FBML tags: For more on FBML tags, please refer to the facebook documentation:
http://developers.facebook.com/docs/reference/fbml/
@connect/authorize url: The connect/authorization url should be the base of your CakePHP Application.
not getting about fbml tags
i m still confused how to use fbml tags in our connect.ctp file.you have used all tags related to xfbml but in my application i have to use FQL query:
In my facebook app i used to fire this type of query:
$user = $facebook->require_login();
$fql = 'SELECT uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1='.$user.') AND is_app_user = 1';
$_friends = $facebook->api_client->fql_query($fql);
so how can we use this type of queries in this plugin..Because i have tried this query but it didnt work..plz help me. thank you.
Use graph system.
http://developers.facebook.com/docs/api
At first glance it looks like you're trying to get the friends of a logged in user. First, on your login you'll need to ask for the friends permission and then you can preform the graph call to me/friends.
Alternatively you can always install the old deprecated version of the facebook plugin, although Facebook has announced those type of queries will not work eventually. Just FYI.
Download latest release of deprecated API: http://github.com/webtechnick/CakePHP-Facebook-Plugin/tarball/v1.6.1
Hope that helps,
Nick
FQL
http://developers.facebook.com/docs/reference/fql/
You can make a restful apicall with the plugin like so.
This is straight out of the facebook PHP SDK (vendors/facebook/php/facebook.php) included in the plugin.
This is still deprecated, use with caution.
Hope that helps,
Nick
Thanx a lot.
Logout?
Custom Button
CSS is as follows:
.fb_button.fb_button_medium {
background-color:transparent !important;
background-image:url("PATH_TO_IMAGE") !important;
background-position:left top !important;
background-repeat:no-repeat !important;
height:40px !important;
text-indent:-5000px;
width:300px !important;
Re: Custom Button
I'd rather have one logout link (text, my own). Or maybe there is something the Graph API for that which I can work around.
Thanks
Logout Response
The "Custom Button" entry was in response to a question I posted a few days ago. I know some people are probably stuck like me on obvious questions so I thought I would share. Hopefully it helps someone in the future.
Re:
Local development
localhost
regarding Friends's list
Plz help me.
I have tried out but i m not getting any of my facebook friends
In my users_controller:
var $name = 'Users';
var $helpers = array('Html','Form','Javascript','Ajax','RfRating','Session');
var $components = array('Auth','RfRating', 'RequestHandler','Session');
var $uses = array('User','Databasebkup','Article', 'Vote');
function inde)
{
App::import('Lib','Facebook.FB');
$Facebook = new FB();
$results = $Facebook->api('/me/friends');
print_r($results);
}
function login() {
if ($this->Auth->user())
{
$this->redirect($this->Auth->redirect('users/index'));
}
}
if you feel then plz give me your example and then i will try with that.
plz guide me.
I want to use now facebook graph system only and i have put the code as you have said but still not working..plz give me with working example might be that helps me..
function logout
logout(array( 'redirect' => '/users/logout' ));
this generate FB.Connect.logoutAndRedirect(/users/logout)
When i click on this link, it doesn't work. This is the error message from firebug
"invalid regular expression flag l"
re:function logout
It should be:
Make sure you're using the most recent facebook plugin 2.0.3.
helper modified
It works only if you make a page refresh after the login. If you don't make it, when i click in the logout button i've the following error in firebug console "users it's not defined", and in google chrome inspect the error is
"Uncaught ReferenceError: users is not defined"
"FB.logout() called without a session."
But there is a session. Any idea?
re:helper modified
By the way, your modifications have a mistake, you have to wrap the redirect in ticks, as right now you're assigning
window.location = /users/logout
which doesn't make sense. It should be:
window.location = '/users/logout'
But this is all done for you with the latest Facebook helper. So upgrading is the best solution to this problem.
Thanks,
Nick
ok.
Now I'm trying to find a way to set up the cancel_url parameter if a user don't allow my application.
Also, it would be good to add some function in the connect component, for example simples functions to post on the wall, or to update the status of the user.
But... great work, your plugin rocks!
Development Environment
Development Environment - More Info
http://forum.developers.facebook.net/viewtopic.php?id=57205
I found a fix for this. It is to do with the SSL certificate on a mamp/wamp setup. See this update for the fix:
http://github.com/facebook/php-sdk/issues#issue/7
basically you want to add CURLOPT_SSL_VERIFYPEER => false to line 94 of the facebook.php in the sdk.
Hope that helps someone else!
Rob.
Development Environment - Solved
Problem with logout
I'm trying to do the simple app and using your component. Everything works well. But I got one problem: if you got user logged in Cake using FB and then this user is logged out of FB (for example, session timeout), logout link doesn't work anymore, because it uses some JS related to current FB session I guess. How to do logout in that case? Oh how to determine that FB session is unavailable and change logout link to simple users/logout without any JS.
Thanks.
Facebook authentication
On facebook developer homepage there is no more Connect section, so where I have to put URL. And... what URL i've to use?
Help!
settings
What is your facebook settings (http://www.facebook.com/developers/apps.php)
for your demo application (http://facebook.webtechnick.com/) ?
Cant have $facebook->share() on same page as other facebook elements
re: facebook share conflicts
Example:
Hope that helps,
Nick
XHTML Valid
Any ideas?
settings
web site -> Site URL
facebook integration -> canvas page
facebook integration -> canvas url
advanced -> JSON Encoding
advanced -> Stream post URL security
advanced -> Canvas Session Parameter
advanced -> OAuth 2.0 for Canvas (beta)