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.


<?php
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');

print_r($page_data);

}

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

One Comment

  1. NK
    Posted December 15, 2011 at 19:13 | Permalink

    This is a good basic example. It’s helpful to see a couple pieces of code from Facebook’s docs combined in one example.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>