Facebook app beginner code example

Since it was not so easy for me to get things up and running, I wanted to share it for other developers. This code gets all videos that are uploaded to a page. First you should download the php sdk from github.

require_once 'facebook.php';

$app_id = "226102437478452"; //Your application ID
$canvas_page = "http://apps.facebook.com/your_canvas_page/"; //Your canvas page
$secret = '1b919de960ba93165650c2385a5b1c7e'; //Your application secret

$auth_url = "http://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&amp;redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {

//this uses the facebook object from facebook.php
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $secret,
$user_id = $facebook->getUser();

//page id
$page_id = '134501956646782';
$page_data = $facebook->api('/'.$page_id.'/videos/uploaded');




This entry was posted in Facebook. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.