• Login with Facebook – tas patiesībā ir graujoši vienkārši

    Pirmā koda daļa nodrošina pliku pieslēgšanos.
    Atliek vien noreģistrēt savu websaitu “facebook apps” un iegūt APP_ID, APP_SECRET utt.
    <fb:login-button autologoutlink="true" style="display:table-cell;padding:3px;" ></fb:login-button>
    <p><fb:like></fb:like></p>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
    FB.init({appId: '235xxxxxxxxxxxxxxx', status: true, cookie: true,
    xfbml: true});
    };
    (function() {
    var e = document.createElement('script');
    e.type = 'text/javascript';
    e.src = document.location.protocol +
    '//connect.facebook.net/lv_LV/all.js';
    e.async = true;
    document.getElementById('fb-root').appendChild(e);
    }());
    </script>

    Lai tiktu pie lietotāja Facebook datiem… spēlējamies tālāk…

    <?php
    define('YOUR_APP_ID', '235xxxxxxxxxxxxxxx');
    define('YOUR_APP_SECRET', 'c9fb5xxxxxxxxxxxxxxxxxxxxxxxxx');

    function get_facebook_cookie($app_id, $app_secret) {
    $args = array();
    parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
    ksort($args);
    $payload = '';
    foreach ($args as $key => $value) {
    if ($key != 'sig') {
    $payload .= $key . '=' . $value;
    }
    }
    if (md5($payload . $app_secret) != $args['sig']) {
    return null;
    }
    return $args;
    }

    $cookie = get_facebook_cookie(YOUR_APP_ID, YOUR_APP_SECRET);

    $user = json_decode(file_get_contents(
    'https://graph.facebook.com/me?access_token=' .
    $cookie['access_token']));

    ?>
    <?php if ($cookie) { ?>
    Welcome <?= $user->name ?>
    <?php print_r($user); ?>
    <?php } else { ?>
    <fb:login-button></fb:login-button>
    <?php } ?>
    <div id="fb-root"></div>
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
    FB.init({appId: '<?= YOUR_APP_ID ?>', status: true,
    cookie: true, xfbml: true});
    FB.Event.subscribe('auth.login', function(response) {
    window.location.reload();
    });
    </script>


1111111