Using the new Facebook PHP SDK 3.0 with offline access
As Facebook recently launched the new SDK which follows the oAuth 2.0 [1]. There are couple of things which you need to keep in mind and modify your code so that your app works fine !!
- getSession() function is removed and getUser() is added which just returns the UID ( if not authenticated then 0). Earlier getSession used to also return the access token, sig, expires incase of offline_access permission
- Two files instead of one : base_facebook.php and facebook.php. Basically, there an extra class added (BaseFacebook)
According to [1] :
The login code is now:
$facebook = new Facebook(…);
$user = $facebook->getUser();
if ($user) {
// proceed knowing you have a logged in user who's authenticated
} else {
// proceed knowing you require user login and/or authentication
}
Offline Access
Earlier we just used getSession() to retireve access_token, sig and expires then store it in our DB. Now, we have to use getAccessToken() which returns the access_token and can be stored in the DB.
When you need to make an API call, then you can call setAccessToken() with access_token stored in our DB as parameter. Then, you make the call.
All Apps must implement the oAuth flow by 1st September, 2011, so its better to start working now.
[1] http://developers.facebook.com/blog/post/503
If you have anything to add, please leave it as a comment
This entry was posted on Saturday, June 11th, 2011 at 11:50 pm and is filed under Information, PHP. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

