douxian1939 2014-08-23 17:06
浏览 505
已采纳

我如何获得Facebook用户名?

Im a totally facebook newbie developer.This is the sdk version that i use: click . This is the login part:

<?php 
    require '../src/facebook.php';

    $facebook = new Facebook(array(
      'appId'  => 'XXXXXXXXXXXXXXXX',
      'secret' => 'XXXXXXXXXXXXXXXXXx',
      'cookie' => true
    ));
?>

<?php
    $loginUrl = $facebook->getLoginUrl(array ( 
            'scope'     => 'email',
            'redirect_uri' => 'http://facebook.ebis-servicii.ro/mytest/test.php'
            ));

    $user = $facebook->getUser();
    echo '<a href = "'.$loginUrl.'">Login Here </a> ';

?>

And this is the part where I want to get some informations about the user:

<?php
    require '../src/facebook.php';
    $facebook = new Facebook(array(
          'appId'  => 'XXXXXXXXXXXXX',
          'secret' => 'XXXXXXXXXXXXX',
          'cookie' => true
        ));
    $user = $facebook->getUser();

    if ($user) {
        try{
            $user_profile = $facebook->api('/me');
            var_dump($user_profile);
            $fbid = $user_profile['id'];                 // To Get Facebook ID
            $fbuname = $user_profile['username'];  // To Get Facebook Username
            $fbfullname = $user_profile['name']; // To Get Facebook full name
            $femail = $user_profile['email'];    // To Get Facebook email ID
        }catch (FacebookApiException $e) {
            error_log($e);
            $user = null;
        }

        echo "FBID ".$fbid."<br>";
        echo "Email ".$femail."<br>";
        echo "Name ".$fbfullname."<br>";
        echo "Username ".$fbuname."<br>";

        echo "Facebook Picture:<br>";
        //echo '<img src="https://graph.facebook.com/'.$_SESSION["USERNAME"].'>;
        echo "<img src ='https://graph.facebook.com/".$fbuname."'>";
    }
?>

This is the url link where you see the results. So my question is how do I get the username? In the result of the var dump there is no username .

  • 写回答

1条回答 默认 最新

  • dtwupu6414 2014-08-23 17:17
    关注

    Since v2.0, the username is not included in the result anymore, as you can see in the Facebook docs: https://developers.facebook.com/docs/graph-api/reference/v2.1/user

    Else, the App Scoped IDs would be pointless, and they came with v2.0 too. Apps should not be able to get to the "real" profile of the users.

    You should be able to use the App Scoped ID to show the user picture:

    echo '<img src="https://graph.facebook.com/'.$fbid.'/picture?width=121&height=100" />';
    

    Btw, i would suggest using the new PHP SDK (4.x) for new Apps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集