Esempio n. 1
0
 * under the License.
 */
require '../src/Facebook/Facebook.php';
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook\Facebook(array('appId' => '191149314281714', 'secret' => '73b67bf1c825fa47efae70a46c18906b'));
// Get User ID
$user = $facebook->getUser();
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (Facebook\FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}
// Login or logout url will be needed depending on current user state.
if ($user) {
    $logoutUrl = $facebook->getLogoutUrl();
} else {
    $loginUrl = $facebook->getLoginUrl();
}
// This call will always work since we are fetching public data.
$naitik = $facebook->api('/naitik');
?>
<!doctype html>
Esempio n. 2
0
<?php

require '../src/Facebook/Facebook.php';
$facebook = new Facebook\Facebook(array('appId' => '191149314281714', 'secret' => '73b67bf1c825fa47efae70a46c18906b'));
// See if there is a user from a cookie
$user = $facebook->getUser();
if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
    } catch (Facebook\FacebookApiException $e) {
        echo '<pre>' . htmlspecialchars(print_r($e, true)) . '</pre>';
        $user = null;
    }
}
?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php 
if ($user) {
    ?>
      Your user profile is
      <pre>
        <?php 
    print htmlspecialchars(print_r($user_profile, true));
    ?>
      </pre>
    <?php 
} else {
    ?>