necromancer
necromancer

Reputation: 23

How i can get user email and name with Facebook connect new platform

i am using facebook connect with new platform in my asp.net web site which is in 2.0. i want to get user email and name. how i can do that. Regards.

Upvotes: 2

Views: 24387

Answers (1)

Rafee
Rafee

Reputation: 4078

Email address and other information of user from Facebook, with users permission

Before this you should have

Facebook app id and secret id , these values can be created from below link, when you are logged into facebook

https://developers.facebook.com/apps

follow steps to create apps and you will keys automatically

enter image description here

Step 0

make a test.php and below contents

 <html>
    <head>
      <title>My Facebook Login Page</title>
    </head>
    <body>
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          FB.init({
            appId      : 'YOUR_APP_ID',
            status     : true, 
            cookie     : true,
            xfbml      : true,
            oauth      : true,
          });
        };
        (function(d){
           var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
           js = d.createElement('script'); js.id = id; js.async = true;
           js.src = "//connect.facebook.net/en_US/all.js";
           d.getElementsByTagName('head')[0].appendChild(js);
         }(document));
      </script>
      <div class="fb-login-button" scope="email,user_checkins">
        Login with Facebook
      </div>
    </body>
 </html>

enter image description here

Step 1

Download Facebook php-sdk from below link

https://github.com/facebook/php-sdk update 23 dec 2012 https://github.com/facebook/facebook-php-sdk

paste it your working directory and extract and rename it as facebook-php-sdk

Step 2

https://developers.facebook.com/docs/guides/web/

you can copy below code from above link,

or below code fully functional and perfectly made for retriving email and other information

 <?php

    define('YOUR_APP_ID', '99999998558585');

    //uses the PHP SDK.  Download from https://github.com/facebook/php-sdk
    require 'facebook-php-sdk/facebook.php';

    $facebook = new Facebook(array(
      'appId'  => '99999998558585',
      'secret' => 'h4h23jh4lk23j432j42bdaf',
    ));

    $userId = $facebook->getUser();

    echo "FB User Id : " . $userId;

    $userInfo = $facebook->api('/me');

    echo "<pre>";
    print_r($userInfo);
    echo "</pre>";

?>

and added image for easibility

and final output will be displayed in image

enter image description here

Upvotes: 10

Related Questions