如何使用最新的PHP SDK从Facebook获取fbid,名称,电子邮件

时间:2016-02-10 08:04:38

标签: php facebook facebook-graph-api facebook-php-sdk

需要帮助。

如何使用php sdk登录facebook电子邮件

2 个答案:

答案 0 :(得分:1)

在更改日志中搜索“声明字段”:https://developers.facebook.com/docs/apps/changelog#v2_4

您必须指定要获取的字段,否则您只能获得ID和名称。例如:

/me?fields=name,email

答案 1 :(得分:0)

  1. 包含java脚本FB SDK:

    <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "http://connect.facebook.net/en_US/all.js#xfbml=1&appId=PLACE_YOUR_FB_APP_ID"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>

  2. 发起连接Facebook的链接:

    <script>function FBLogin(){

       FB.login(function(response){
    
         if(response.authResponse){
    
            var USERID  =   response.authResponse.userID;
    
            FB.api('/me', function(userinfo){
                jQuery.ajax({
    
                type:"POST",
    
                url: "ajax_fb_login.php",
    
                data:  "userinfo="+userinfo,
    
                success: function(html){
    
                }
              });
            });
            } 
        }, {scope: 'email,user_likes'});
    }</script>
    
  3. 检索php文件中的facebook数据:

    $ fbid = $ _REQUEST ['userinfo'] ['id'];     $ email = $ _REQUEST ['userinfo'] ['email'];     $ first_name = $ _REQUEST ['userinfo'] ['first_name'];     $ last_name = $ _REQUEST ['userinfo'] ['last_name'];     $ fb_name = $ _REQUEST ['userinfo'] ['name'];