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

房东的猫 提交于 2019-11-27 06:29:23

问题


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.


回答1:


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

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>

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




回答2:


These two links will help you.

Authentication specially Authenticating users in a web application section

Extended Permissions



来源:https://stackoverflow.com/questions/2718722/how-i-can-get-user-email-and-name-with-facebook-connect-new-platform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!