1

I'm totally new in Facebook and I want to do the following

  1. User will come to my page and automatically redirect to facebook for specifying login credentials.

  2. After that he will get redirected to my page. I want to know the user's ID, display name and profile pic.

How can I do it using php?

thanks a lot!!!

Vladimir

Online

1 Answer 1

3

You can use the Facebook PHP SDK (see on github). So you will have something like :

require "facebook.php"; $facebook = new Facebook(array( 'appId' => YOUR_APP_ID, 'secret' => YOUR_APP_SECRET, )); $user = $facebook->getUser(); 

You then have to check if you have a valid access token by making an API call. If it does not raise any exception, then you have a valid access token :

if ($user) { try { $user_profile = $facebook->api('/me'); } catch (FacebookApiException $e) { $user = null; } } 

You need then to display the login or logout link :

<?php if ($user): ?> <a href="<?php echo $facebook->getLogoutUrl() ?>">Logout of Facebook</a> <?php else: ?> <a href="<?php echo $facebook->getLoginUrl() ?>">Login with Facebook</a> <?php endif ?> 

All the info you ask for are stored in the the array $user_profile, you can trying a var_dump($user_profile) to see where they are.

you may want to check the example page of the Facebook PHP SDK which is well documented.

Hope that helps.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.