dougu3290 2013-09-24 17:31
浏览 50
已采纳

如果只登录facebook php sdk,请获取Facebook用户

I want to get current loggedin facebook user in php sdk. Here is what i have tried:

$facebook = new \Facebook(array(
        'appId' => 'XXXXXXXXXXX',
        'secret' => 'XXXXXXXXXXXXXXXXXXXXX',
    ));
$user = $facebook->getUser();
var_dump($user);
if ($user) {
   $logoutUrl = $facebook->getLogoutUrl();
   echo $logoutUrl;
} else {
   $loginUrl = $facebook->getLoginUrl();
   echo $loginUrl;
}

When I load the page with above code, I get the loginUrl even though I am logged in facebook. Only when i load $loginUrl in the browser, I am able to get facebook user.

How do I get the current user at first load of this page?

  • 写回答

2条回答 默认 最新

  • dsf5989 2013-09-24 21:29
    关注

    I get the loginUrl even though I am logged in facebook.

    Of course you do – being logged in to facebook.com is something completely different than being logged in to your app.

    Only when i load $loginUrl in the browser, I am able to get facebook user.

    That’s because after that the user is logged in to your application.

    How do I get the current user at first load of this page?

    Only possible for users who have connected to your app already at some point before, by using the JavaScript SDK.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥15 QT6颜色选择对话框显示不完整
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥15 DS18B20内部ADC模数转换器