Site icon Web Niraj

Facebook API: Creating Page Apps using Facebook PHP SDK 4.0.x

The way you create Facebook Page Applications has also changed when using the new Facebook PHP SDK v4.0.x. This tutorial shows you how to setup a basic Tab App using PHP SDK v4.0.7 or later. The FacebookPageTabHelper class makes it easy to determine the page_id, adding in a like gate and checking if the user is an administrator.

Unfortunately, the new PHP SDK also doesn’t yet support the app_data parameter you can pass to the Page URL. I’ve submitted a pull request to fix this issue, and awaiting Facebook to add it into the SDK.

Anyway, to create Page Apps, you need to make sure you include to additional classes from the SDK if they’re not already included:

These two classes will provide new functions to make retrieving a session from the Page Tab easier. Most of the code remains the same as my previous tutorial, but I’ve included the complete code below:

See the gist on github.

The new FacebookPageTabHelper depends on the FacebookCanvasLoginHelper to provide functions to get the session from the Page or Canvas (wither via POST or GET). Using the helper, you can easily create a likegate using the $pageHelper->isLiked() function:

See the gist on github.

UPDATE #1 – July 2nd 2014

Facebook has updated the PHP SDK to v4.0.9, which has broken my original code. I have since updated the above code to work with the latest version of the SDK. You can see my revisions here. The new version introduced the file FacebookSignedRequestFromInputHelper.php, which caused the previous code to break.

Exit mobile version