简体   繁体   中英

Two ways of loging in Facebook using php?

I'm really confused about loging in facebook. It seems that there are two ways of loging in one is the way that shows on the facebook howtos page :

And the other is by using this code:

require_once('facebook.php');
session_start();
$config = array(
    'appId' => "xxxxxxx",
    'secret' => "xxxxxxxxxxxxx"
);

$facebook = new Facebook($config);
$user_id = $facebook->getUser();

if ($user_id) 
{
   try 
   {
        echo $user_id;
   }
   catch (FacebookApiException $e) 
   {
         $login_url = $facebook->getLoginUrl();
          echo 'Please <a href="' . $login_url . '">login.</a>';
    }
} 
else 
{
   $login_url = $facebook->getLoginUrl();
   echo 'Please <a href="' . $login_url . '">login.</a>';
}

Which one is the best? What are the cons and pros for each method? If I use the first one, can I instanciate a facebook object in order to perform my graph api calls without having to append the access token on the graph url?

Thank you.

The two "ways" you talk about are identical. Well nearly.

In the code you mentioned above is an old way of accessing Facebook. The reason it is still valid is because Facebook took many of the calls your doing and made them into easier to access functions on their side.

So the quality of the methods are essentially identical but I'd still suggest the new way in case of any major API change X years from now.

If you use the new way no you have to append your Access token to use the Graph API.

You could instantiate a Facebook object but its the same argument as above. May not work X years from now

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM