Example #1
0
					method: 'feed',
					name: 'Silver Rhapsody Jewelry Design Giveaway',
					description: "I entered the @SilverRhapsodyDesigns Giveaway to win a TBD.",
					link: 'http://www.facebook.com/SilverRhapsodyDesigns',
					picture: '<?php 
echo AppInfo::getUrl('/images/fbthumb.jpg');
?>
'
				};

				FB.ui(args, null);
			};

			FB.init({
				appId: '<?php 
echo AppInfo::appID();
?>
',
				channelUrl: '//<?php 
echo $_SERVER["HTTP_HOST"];
?>
/channel.html',
				status: true,
				cookie: true,
				xfbml: true,
				logging: true
			});


			FB.Canvas.setAutoGrow();
		};
require_once 'facebook/src/facebook.php';
// Load our own libraries.
require 'pat-fb/PATFacebookUser.class.php';
require 'pat-fb/PATIncident.class.php';
require 'pat-fb/template_functions.inc.php';
$FB = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret(), 'trustForwarded' => true));
$user_id = $FB->getUser();
if ($user_id) {
    try {
        // Fetch the viewer's basic information
        $me = new PATFacebookUser($FB);
        $me->loadFriends('id,name,gender,picture.type(square),bio,installed');
        $my_prefs = $me->getPreferences();
        date_default_timezone_set($my_prefs['user_timezone_name']);
    } catch (FacebookApiException $e) {
        error_log('Failed to set global variable $me.');
        error_log(serialize($e));
        // If the call fails we check if we still have a user. The user will be
        // cleared if the error is because of an invalid accesstoken
        if (!$FB->getAccessToken()) {
            header('Location: ' . AppInfo::getUrl($_SERVER['REQUEST_URI']));
            exit;
        }
    }
}
// Some global variables.
$FBApp = new AppInfo($FB->api('/' . AppInfo::appID()));
$db = new PATFacebookDatabase();
$db->connect(psqlConnectionStringFromDatabaseUrl());
// Links to "help" screens.
define('DOCUMENTATION_URL_BASE', 'https://github.com/meitar/pat-facebook/wiki');
<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);
// Loading SLIM
require 'slim/Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new Slim\Slim();
require_once "src/AppInfo.php";
require_once "src/Utils.php";
// LOADING FACEBOOK
require_once 'sdk/src/facebook.php';
$facebook = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret(), 'sharedSession' => true, 'trustForwarded' => true));
$app->get('/hello/:name', function ($name) use($app) {
    $app->render('show.php', array('title' => 'Sahara'));
    echo "Hello, {$name}";
});
$app->get('/', function ($name = "Demo app Open graph") use($app, $facebook) {
    $user_id = $facebook->getUser();
    //$app_info = $facebook->api('/'. AppInfo::appID());
    //$app_name = Utils::idx($app_info, 'name', '');
    $app->render('main.php', array('user_id' => $user_id, "title" => "DEMO APP FB OG"));
});
$app->get("/maps/streetview", function () use($app, $facebook) {
    $user_id = $facebook->getUser();
    $app->render('map_streetview.php', array('user_id' => $user_id, "title" => "Street View"));
});
$app->get('/info', function () {
    phpinfo();
});
$app->run();
Example #4
0
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
***/
// Provides access to app specific values such as your app id and app secret.
// Defined in 'AppInfo.php'
require_once 'AppInfo.php';
// Enforce https on production
if (substr(AppInfo::getUrl(), 0, 8) != 'https://' && $_SERVER['REMOTE_ADDR'] != '127.0.0.1') {
    header('Location: https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
    exit;
}
require_once 'classes.php';
require_once 'utils.php';
require_once 'database.php';
require_once 'sdk/src/facebook.php';
$db = new Database(new PDO(AppInfo::getDatabaseDSN(), null, null, array(PDO::ATTR_PERSISTENT => true)));
$facebook = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret()));
$user_id = $facebook->getUser();
if ($user_id) {
    try {
        // Fetch the viewer's basic information
        $myfb = $facebook->api('/me');
    } catch (FacebookApiException $e) {
        // If the call fails we check if we still have a user. The user will be
        // cleared if the error is because of an invalid accesstoken
        if (!$facebook->getUser()) {
            header('Location: ' . AppInfo::getUrl($_SERVER['REQUEST_URI']));
            exit;
        }
    }
    $authenticated = true;
} else {
Example #5
0
 /**
  * Authenticates the current viewer of the app, prompting them to login and
  * grant permissions if necessary.  For more information, check the
  * 'https://developers.facebook.com/docs/authentication/'
  *
  * @return app access token if login is successful
  */
 public static function login($redirect)
 {
     $app_id = AppInfo::appID();
     $app_secret = AppInfo::appSecret();
     $home = AppInfo::getHome();
     // Scope defines what permissions that we are asking the user to grant.
     // In this example, we are asking for the ability to publish stories
     // about using the app, access to what the user likes, and to be able
     // to use their pictures.  You should rewrite this scope with whatever
     // permissions your app needs.
     // See https://developers.facebook.com/docs/reference/api/permissions/
     // for a full list of permissions
     $scope = 'user_likes,user_photos,user_photo_video_tags';
     session_start();
     $code = $_REQUEST["code"];
     // If we don't have a code returned from Facebook, the first step is to get
     // that code
     if (empty($code)) {
         // CSRF protection - for more information, look at 'Security Considerations'
         // at 'https://developers.facebook.com/docs/authentication/'
         $state = md5(uniqid(rand(), TRUE));
         setcookie(AppInfo::appID() . '-fb-app', $state, $expires = 0, $path = "", $domain = "", $secure = "", $httponly = true);
         // Now form the login URL that you will use to authorize your app
         $authorize_url = "https://www.facebook.com/dialog/oauth?client_id={$app_id}" . "&redirect_uri={$home}&state=" . $state . "&scope={$scope}";
         // Now we redirect the user to the login page
         echo "<script> top.location.href='" . $authorize_url . "'</script>";
         return false;
         // Once we have that code, we can now request an access-token.  We check to
         // ensure that the state has remained the same.
     } else {
         if ($_REQUEST['state'] === $_COOKIE[AppInfo::appID() . '-fb-app']) {
             $ch = curl_init("https://graph.facebook.com/oauth/access_token");
             curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id={$app_id}&redirect_uri={$home}&client_secret={$app_secret}" . "&code={$code}&scope={$scope}");
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             // Once we get a response, we then parse it to extract the access token
             parse_str($response, $params);
             $token = $params['access_token'];
             return $token;
             // In the event that the two states do not match, we return false to signify
             // that something has gone wrong during authentication
         } else {
             echo "States do not match.  CSRF?";
             return false;
         }
     }
 }
Example #6
0
?>
</title>
    <link rel="stylesheet" href="stylesheets/screen.css" media="screen">

    <!-- These are Open Graph tags.  They add meta data to your  -->
    <!-- site that facebook uses when your content is shared     -->
    <!-- over facebook.  You should fill these tags in with      -->
    <!-- your data.  To learn more about Open Graph, visit       -->
    <!-- 'https://developers.facebook.com/docs/opengraph/'       -->
    <meta property="og:title" content=""/>
    <meta property="og:type" content=""/>
    <meta property="og:url" content=""/>
    <meta property="og:image" content=""/>
    <meta property="og:site_name" content=""/>
    <?php 
echo '<meta property="fb:app_id" content="' . AppInfo::appID() . '" />';
?>



<!-- START  Edited by Ravi Desai at 05-11-2011 17:16:56   -->

<script language="JavaScript">

var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
var days = new Array("S", "M", "T", "W", "T", "F", "S");

today = new getToday();	
var element_id;
var temp;
        }
    }
    // This fetches some things that you like . 'limit=*" only returns * values.
    // To see the format of the data you are retrieving, use the "Graph API
    // Explorer" which is at https://developers.facebook.com/tools/explorer/
    $likes = idx($facebook->api('/me/likes?limit=4'), 'data', array());
    // This fetches 4 of your friends.
    $friends = idx($facebook->api('/me/friends?limit=4'), 'data', array());
    // And this returns 16 of your photos.
    $photos = idx($facebook->api('/me/photos?limit=16'), 'data', array());
    // Here is an example of a FQL call that fetches all of your friends that are
    // using this app
    $app_using_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1'));
}
// Fetch the basic info of the app that they are using
$app_info = $facebook->api('/' . AppInfo::appID());
$app_name = idx($app_info, 'name', '');
?>
<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#">
<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object#">
  <meta property="fb:app_id" content="YOUR_APP_ID" /> 
  <meta property="og:type"   content="object" /> 
  <meta property="og:url"    content="Put your own URL to the object here" /> 
  <meta property="og:title"  content="Sample Object" /> 
  <meta property="og:image"  content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" /> 
    <!-- <script src="/javascript/track.js" type="text/javascript"></script> -->

    <title>CAAT example: Actors across a Path and Interpolators</title>

    <link rel="stylesheet" href="/style/demo.css">