I am new to PHP and it is very difficult for me to understand facebook login system.
I downloaded three src / gitub files (https://github.com/facebook/php-sdk/). I tried using the example.php file to get started. However, I'm not sure what to do with it.
For those unfamiliar with the file, here is a copy of example.php, with the style removed:
require '../src/facebook.php'; $facebook = new Facebook(array( 'appId' => '...', 'secret' => '...', )); $user = $facebook->getUser(); if ($user) { try { $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { error_log($e); $user = null; } } if ($user) { $logoutUrl = $facebook->getLogoutUrl(); } else { $loginUrl = $facebook->getLoginUrl(); } $naitik = $facebook->api('/naitik'); ?> <!doctype html> <html xmlns:fb="http://www.facebook.com/2008/fbml"> <body> <?php if ($user): ?> <a href="<?php echo $logoutUrl; ?>">Logout</a> <?php else: ?> <div> Login using OAuth 2.0 handled by the PHP SDK: <a href="<?php echo $loginUrl; ?>">Login with Facebook</a> </div> <?php endif ?> <h3>PHP Session</h3> <pre><?php print_r($_SESSION); ?></pre> <?php if ($user): ?> <h3>You</h3> <img src="https://graph.facebook.com/<?php echo $user; ?>/picture"> <h3>Your User Object (/me)</h3> <pre><?php print_r($user_profile); ?></pre> <?php else: ?> <strong><em>You are not Connected.</em></strong> <?php endif ?> <h3>Public profile of Naitik</h3> <img src="https://graph.facebook.com/naitik/picture"> <?php echo $naitik['name']; ?> </body> </html>
Here are my questions about this:
1) What about cookies? - I want the user to be able to log into my site after re-opening his browser.
2) What is the minimum minimum I need to get from this example.php file to check / register a user, start a session, save the session in a cookie, get the user fb user ID, name fb, fb image and friend list fb?
3) There is one fb_ca_chain_bundle.crt file in src / files, and I am completely unfamiliar with what a file is, and I'm not sure if it is even necessary. What is his purpose?
4) Line $naitik = $facebook->api('/naitik'); is the "naitik" username of this person, so if I type facebook.com/naitik, will he show his public profile? replaces "/ naitik" with "/ me", what will get a public profile of a person registered on facebook?
5) How to get an access token and how to use it in my code?
6) When I create a session for the user and a cookie so that the user logs in after re-opening the browser, what should I accurately store cookies in my sessions?
I know this is a lot of questions, but I looked through a lot of guides on the Internet, and none of them did a good job explaining this, mainly because they simply reference the Github PHP-SDK files. In addition, most of them explain the previous version of the PHP-SDK. Any help is appreciated with any of the questions.